开发者

Objective-C++ compiles for iPhone, but not simulator

开发者 https://www.devze.com 2022-12-26 10:54 出处:网络
I have a C++ library I want to add to my 开发者_运维知识库iphone project. In one header file I declare

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++.

0

精彩评论

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