跳转至

静态数据成员

约 10 个字 18 行代码

定义

class P {
public:
    static int a;
    static int b;
    const int c
};
int P::a = 5;  //两种定义类外定义方式
int P::b;
int main() {
    P::b = 5; //这里不能加int
    cout << P::a<<endl;
    cout << P::b<<endl;
}

访问

cout << P::a<<endl;
//注意要用:: 而不是.

//静态成员函数也用::

颜色主题调整

评论区~

有用的话请给我个赞和 star => GitHub stars
快来跟我聊天~