为什么我不能使用'this->'访问非静态函数中的静态成员?

san*_*sht 0 c++ oop this

为什么它给我一个链接错误?我认为用静态成员访问是可以的this->x.逻辑上听起来不错.我猜一个实例指针可以根据OOPS概念访问类拥有的内容.

son*_*yao 6

您还需要定义静态成员变量.例如:

// in .h
class some_class {
    static int v;  // it's just a declaration
};

// in .cpp
int some_class::v; // here's the defination
Run Code Online (Sandbox Code Playgroud)