开发者

Using static field from C++ class in ObjectiveC code

I have part of my code written in C++ and I would like to use this code from within ObjectiveC code. In the C++ code I have a class with a static fields. In ObjC code I set these fields and try to read them later. However, when I read the values of these fields I get some rubbish.

The code looks more less like this, in one class I have:

   CCommunication::portNumber = 7777; //some value

later in another class I have:

int portNo = CCommunication::portNumber; //and here I get some rubbish values

To make this even stranger sometimes when I r开发者_StackOverflow中文版un the same code on my iPhone connected to my Mac it works well and when I run this code on the iPhone not connected to the Mac the code works like broken.

Any ideas?


You should define public accessors in the class CCommunication that will return these static values, then you should be able to call those accessors from within an objective-c class, as long as that class is implemented within an objective-c++ file (*.mm).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜