C++ 如何在构造函数的静态列表中添加对象 #包括 使用名称空间std; 课堂测试{ 公众: Test(){objects.push_front(this);} 私人: 静态前向对象; }; int main(){ 试验a; }//Visual Studio 17,错误
VisualStudio没有说明问题所在。它只是重新运行这两个代码——LNK1120和LNK2001。您有一个未定义的对C++ 如何在构造函数的静态列表中添加对象 #包括 使用名称空间std; 课堂测试{ 公众: Test(){objects.push_front(this);} 私人: 静态前向对象; }; int main(){ 试验a; }//Visual Studio 17,错误,c++,static,visual-studio-2017,C++,Static,Visual Studio 2017,VisualStudio没有说明问题所在。它只是重新运行这两个代码——LNK1120和LNK2001。您有一个未定义的对静态转发\u列表对象的引用您必须定义静态对象,如下所示: #include <forward_list> using namespace std; class Test { public: Test(){objects.push_front(this);} private: static forward_list<Test*>obj
静态转发\u列表对象的引用代码>您必须定义静态对象,如下所示:
#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
#包括
使用名称空间std;
课堂测试{
公众:
Test(){objects.push_front(this);}
私人:
静态前向对象;
};
前向列表测试::对象;
int main(){
试验a;
}//Visual Studio 17,错误
您有一个未定义的对静态转发\u列表对象的引用代码>您必须定义静态对象,如下所示:
#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
#包括
使用名称空间std;
课堂测试{
公众:
Test(){objects.push_front(this);}
私人:
静态前向对象;
};
前向列表测试::对象;
int main(){
试验a;
}//Visual Studio 17,错误