为什么以下用法会给我一个错误:未定义的对“Environment::self”的引用所以下面是我的测试用例,类就在它下面,标题和cpp:测试:
Environment bla;
bla=Environment::CTE;
if(bla==1){
printf("CTE!");
}else if(bla==Environment::PPE){
printf("NO: its ppe");
}
标题:
class Environment{
public:
enum{CTE, PTE, PPE, LOCALHOST};
static int self;
bool operator==(const int& rhs)const;
Environment& operator=(const int &rhs);
};
和 CPP:
#include "Environment.h"
bool Environment::operator==(const int& rhs)const{
if (this->self ==rhs)
return true;
return false;
}
Environment& Environment::operator=(const int &rhs) {
if (this->self != rhs) {
this->self=rhs;
}
return *this;
}