#include <iostream>
using namespace std;
class Assn2
{
public:
static void set_numberofshape();
static void increase_numberofshape();
private:
static int numberofshape22;
};
void Assn2::increase_numberofshape()
{
numberofshape22++;
}
void Assn2::set_numberofshape()
{
numberofshape22=0;
} // there is a problem with my static function declaration
int main()
{
Assn2::set_numberofshape();
}
为什么在编译时出现错误
undefined reference to Assn2::numberofshape22
?我正在尝试声明一个静态整数:numberofshape22和两个方法。
方法1将shape22的数量增加1
方法2将numberofshape22初始化为0
我究竟做错了什么 ??
最佳答案
您刚刚声明了变量。您需要定义它:
int Assn2::numberofshape22;
关于c++ - 未定义对静态变量和静态方法的引用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19478640/