I have a C++ library I want to add to my 开发者_运维知识库iphone project.
In one header file I declare
@interface a
{
cppvirtualclass V;
}
This compiles fine for the iPhone device with Release settings. However it refuses to compile for the Simulator with or without debug info.
It give the error
error: type 'V' has virtual member functions.
Is there a way out of this or do I have to define only concrete C++ classes?
By default Objective C does not run constructors on C++ instance variables when it creates Objective C objects. This means (I think) that the C++ object's vtable will not get initialised correctly.
Try making your instance variable a pointer and allocating it in the init method (and destroying it in dealloc/finalize).
Or
try setting "Call C++ default Ctors/Dtors in Ovjective-C" in your target code generation settings.
(GCC_OBJC_CALL_CXX_CDTORS, -fobjc-call-cxx-cdtors)
Also, Objective-C++ is no longer a permitted language for iPhone development (per 4.0). You can use Objective-C, C and C++, but not Objective-C++.
精彩评论