简体   繁体   English

Objective-C ++ C ++对象析构函数

[英]Objective-C++ C++ object destructor

I have an Objective-C class which one of it's variables is an C++ object (most of my code is C++, but I need some ObjC classes to integrate with iOS libraries). 我有一个Objective-C类,其中一个变量是一个C ++对象(我的大部分代码都是C ++,但我需要一些ObjC类来与iOS库集成)。 Does Objective-C++ guarantees that the C++ object will be correctly destroyed when the Objective-C object is destroyed? Objective-C ++是否保证在销毁Objective-C对象时正确销毁C ++对象?

Some example code: 一些示例代码:

class MyCppClass {
    // ...
};

@interface MyObjCClass : NSObject {
    MyCppClass myCppObject; // is it ok to do it?
}

// ...

@end

Yes. 是。 After the -dealloc method is called, a hidden .cxx_destruct method is called. 调用-dealloc方法后,将调用隐藏的.cxx_destruct方法。 This method calls all the destructors of all instance variables that have a destructor. 此方法调用具有析构函数的所有实例变量的所有析构函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM