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.

链接地址: http://www.djcxy.com/p/51262.html

上一篇: 我如何了解“封闭”使用情况?

下一篇: C ++头文件的C ++实现?