【c++】访问静态成员变量出现undefined reference to
以下是类的定义:classitem{public:item(intnumber=1);intgetNumber()const;boolisRightOption(into...
以下是类的定义:
class item
{
public:
item(int number=1);
int getNumber()const;
bool isRightOption(int option);
static void printAnswers();
private:
int number;
item *next[4];
static array<int,10> answers;
bool conditionJurdge(int option)const;
bool con1(int option)const;
bool con2(int option)const;
bool con3(int option)const;
bool con4(int option)const;
bool con5(int option)const;
bool con6(int option)const;
bool con7(int option)const;
bool con8(int option)const;
bool con9(int option)const;
bool con10(int option)const;
};
array<int,10> answers;
以下是编译出错的那个静态成员函数:
void item::printAnswers(){
cout << "function called" << endl;
for(size_t i=0;i<10;i++){
cout << answers[i] << " ";
}
}
错误信息C:\Users\123\Desktop\newWay\item.cpp:36: error: undefined reference to `item::answers'
和collect2.exe:-1: error: error: ld returned 1 exit status 展开
class item
{
public:
item(int number=1);
int getNumber()const;
bool isRightOption(int option);
static void printAnswers();
private:
int number;
item *next[4];
static array<int,10> answers;
bool conditionJurdge(int option)const;
bool con1(int option)const;
bool con2(int option)const;
bool con3(int option)const;
bool con4(int option)const;
bool con5(int option)const;
bool con6(int option)const;
bool con7(int option)const;
bool con8(int option)const;
bool con9(int option)const;
bool con10(int option)const;
};
array<int,10> answers;
以下是编译出错的那个静态成员函数:
void item::printAnswers(){
cout << "function called" << endl;
for(size_t i=0;i<10;i++){
cout << answers[i] << " ";
}
}
错误信息C:\Users\123\Desktop\newWay\item.cpp:36: error: undefined reference to `item::answers'
和collect2.exe:-1: error: error: ld returned 1 exit status 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询