我正在大量使用 Objective-C++。我知道虽然我可以在我的 Objective-C 代码中包含 C++ 代码,但反之则不然。我想通过分布式对象将我创建的自定义 C++ 对象出售给我的 Objective-C 进程。当我尝试执行此操作时,我收到以下错误消息:
error: cannot convert ‘custom_class*’ to ‘objc_object*’ in argument passing
有没有办法将自定义 C++ 对象出售给另一个 Objective-C 进程?
我的代码:
#import <Cocoa/Cocoa.h>
#import <iostream>
#import <stdio.h>
using namespace std;
class custom_class {
public:
custom_class();
~custom_class();
void hello();
};
custom_class::custom_class() { }
custom_class::~custom_class() { }
void custom_class::hello() { cout << "Hello World!" << endl; }
int main() {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
cout << "Starting vendor " << endl;
custom_class *test = new custom_class();
NSConnection *connection = [NSConnection connectionWithReceivePort:[NSPort port] sendPort:nil];
[connection setRequestTimeout:1];
[connection setRootObject:test];
[connection registerName:@"DisObjTest"];
[[NSRunLoop currentRunLoop] run];
[pool drain];
return 0;
}