#include <forward_list>
using namespace std;
class Test {
public:
Test(){objects.push_front(this);}
private:
static forward_list<Test*>objects;
};
int main(){
Test a;
}//Visual Studio 17, error
Visual Studio没有说出问题所在。它只是重新使用这两个代码 - LNK1120和LNK2001。
答案 0 :(得分:4)
您有static forward_list<Test*>objects;
的未定义引用您必须像这样定义static
对象:
#include <forward_list>
using namespace std;
class Test {
public:
Test(){objects.push_front(this);}
private:
static forward_list<Test*>objects;
};
forward_list<Test*> Test::objects;
int main(){
Test a;
}//Visual Studio 17, error