C++ 中的 Objective C 成员班级
是否有可能在 c++ 类中拥有一个客观的 c 成员
@interface ObjectiveCClass : UIViewController {
int someVarialbe;
}
- (void)someFunction;
@end
class CPlusPlusClass{
ObjectiveCClass obj; // have a objective c member
void doSomething(){
obj.someFunction; // and call a objective c method
}
};
任何指导都将非常感激。
干杯
Is it possible to have a objective c member in a c++ class
@interface ObjectiveCClass : UIViewController {
int someVarialbe;
}
- (void)someFunction;
@end
class CPlusPlusClass{
ObjectiveCClass obj; // have a objective c member
void doSomething(){
obj.someFunction; // and call a objective c method
}
};
Any guidance would really be appreciated.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要创建可以在 obj-c 和 cpp 代码之间共享的头文件,您可以使用编译器预定义的宏来执行以下操作:
我不是 100% 确定让 ObjectiveCClassRef 更改类型(如 c/cpp 和 obj-c 之间的类型)是合法的构建。
但是 id 是目标 C 头文件中定义的 ac/cpp 兼容类型,能够存储目标 C 类指针,并且在 .m 或 .mm 文件中使用时,允许您调用该对象直接使用 Objective C 语法。
To create header files that can be shared between obj-c and cpp code, you could use the compiler predefined macros to do something like:
Im not 100% sure its legal to have ObjectiveCClassRef change type like that between c/cpp and obj-c builds.
But
id
is a c/cpp compatible type defined in the objective C header files as capable of storing an objective C class pointer, and, when used in .m or .mm files, allows you to call the object directly using objective C syntax.Objective-C 有一种方言,称为 Objective-C++,它可以与 C++ 互操作,就像 Objective-C 与 C 互操作一样。您可以将文件的设置更改为 Objective-C++,或者将扩展名更改为“.mm” ”。当然,您仍然需要通过指针访问 Objective-C 对象并执行 alloc-init 之类的操作。
There's a dialect of Objective-C called Objective-C++ that is interoperable with C++ the same way that Objective-C is interoperable with C. You can either change the setting for the file to be Objective-C++ or change the extension to ".mm". You'll still need to access Objective-C objects through pointers and do the alloc-init dance and all that, of course.