开发者

Is it possible to build an Objective-C++ implementation from a C++ header?

I have a C++ framework I would like to use in Objective-C++. I'm working in XCode4 and targeting an iPad deployment.

So given this (pseudocode) C++ header:

class A {
public开发者_开发知识库:
    virtual int doSomething(int i) = 0;
private:
    int _i;
}

For this specific instance, I need to have doSomething dispatch something via Grand Central Dispatch.

I'm having trouble finding solutions to implement C++ headers in Objective-C++. Is it possible to do so? If so, can somebody provide a great example?

Thanks!


You can use a C++ framework in Objective C++ as it is. Just include the .h files, and start instantiating classes.

To make sure your sources compile as ObjC++ as opposed to ObjC, make sure your sources have the .mm extension.

Objective C++ is a weird beast - it has two class/object systems running side by side. You can have C++ functions call ObjC methods, and vice versa. What you cannot do though, you cannot derive Objective C classes from C++ classes and vice versa.

I was under impression that you're looking to convert a C++ class library into an ObjC class library. That would be rather time-consuming.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜