Iphone 使用C+中的静态字段+;对象代码中的类 我有一部分代码用C++编写,我想从ObjutVEC代码中使用这个代码。在C++代码中,我有一个带有静态字段的类。在ObjC代码中,我设置了这些字段,并尝试稍后读取它们。然而,当我读取这些字段的值时,我得到了一些垃圾

Iphone 使用C+中的静态字段+;对象代码中的类 我有一部分代码用C++编写,我想从ObjutVEC代码中使用这个代码。在C++代码中,我有一个带有静态字段的类。在ObjC代码中,我设置了这些字段,并尝试稍后读取它们。然而,当我读取这些字段的值时,我得到了一些垃圾,iphone,c++,objective-c,memory-management,ios4,Iphone,C++,Objective C,Memory Management,Ios4,代码看起来不像这样, 在一个班级里,我有: CCommunication::portNumber = 7777; //some value int portNo = CCommunication::portNumber; //and here I get some rubbish values 后来在另一节课上,我有: CCommunication::portNumber = 7777; //some value int portNo = CCommunication::por

代码看起来不像这样, 在一个班级里,我有:

   CCommunication::portNumber = 7777; //some value
int portNo = CCommunication::portNumber; //and here I get some rubbish values
后来在另一节课上,我有:

   CCommunication::portNumber = 7777; //some value
int portNo = CCommunication::portNumber; //and here I get some rubbish values
有时,当我在连接到Mac的iPhone上运行相同的代码时,它工作得很好,而当我在未连接到Mac的iPhone上运行此代码时,代码工作得很好


有什么想法吗?

您应该在类CCommunication中定义公共访问器,该类将返回这些静态值,然后您应该能够从objective-c类中调用这些访问器,只要该类在objective-c++文件(*.mm)中实现。

您最终找到了问题的答案吗?