带字段的静态方法 我现在将Lua与C++结合起来。对于lua,我需要我放在类中的静态方法。我需要静态方法与类中的某些字段进行通信(保存数据),但当我尝试不同的方法时,它失败了。事情是这样的: class CClass{ private: static int a; public: static int f(); }
我尝试以这种方式实现f()方法:带字段的静态方法 我现在将Lua与C++结合起来。对于lua,我需要我放在类中的静态方法。我需要静态方法与类中的某些字段进行通信(保存数据),但当我尝试不同的方法时,它失败了。事情是这样的: class CClass{ private: static int a; public: static int f(); },c++,C++,我尝试以这种方式实现f()方法: int CClass::f() { a = 5; return 0; } 但它给了我一个错误,外部符号无法解析。如何强制方法将我的数据保存在那里 谢谢。大多数静态成员需要在类外定义: class CClass { static int a; // ... }; int CClass::a; // in the .cpp file, not the header
int CClass::f() {
a = 5;
return 0;
}
但它给了我一个错误,外部符号无法解析。如何强制方法将我的数据保存在那里
谢谢。大多数
静态
成员需要在类外定义:
class CClass {
static int a;
// ...
};
int CClass::a; // in the .cpp file, not the header