开发者

How to define a static member in case there is not header file?

开发者 https://www.devze.com 2023-03-02 00:11 出处:网络
How to define a static member in case there is not header file ? The code: class MyClass { }; int MyClass::staticMember;开发者_如何学JAVA// Error: class MyClass has no member staticMember!

How to define a static member in case there is not header file ?

The code:

class MyClass
{
};

int MyClass::staticMember;开发者_如何学JAVA  // Error: class MyClass has no member staticMember!

Any help?


This will work:

//
// Inside .cpp file
//
class MyClass
{
    static int staticMember;
};

int MyClass::staticMember;


If it's not in the class declaration, you can't define it.

0

精彩评论

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