MFC:引用类的静态成员变量

//add.h
class A{
public:
    static x;
    int add();
}

//add.cpp
//当引用类中的静态成员变量时,需先在对应的cpp文件中再定义一次,否则会提示无法解析的外部符号
static A::x;    //再定义一次

int add()
{
    x=0;
}

//test.c
#include "add.h" //首先要包含头文件
int test()
{
    A::x=0;//其次才能引用静态成员变量,且引用时变量前要加上类名::
}

猜你喜欢

转载自blog.csdn.net/zy1049677338/article/details/80695806