如何在构造函数的静态列表中添加对象
How to add object in the static list on the constructor
#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。
你有一个未定义的引用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
相关文章:
- 如何在 sqlite3 中的表中添加整数列表
- 有什么方法可以将元素添加到列表中,如图所示?
- 测试驱动开发 c++:如何将对象添加到向量中,将歌曲添加到播放列表并对其进行测试
- 将新元素添加到列表中,并返回对该元素的引用?
- 可视化 如何将 CString 值列表添加到 MFC C++ 中的组合框中?
- 通过在带有 C++ 的列表中添加连续元素来计算新的整数列表
- CSUF EPP - 你有什么想法(在添加到链接列表末尾时遇到麻烦)
- 将集合的随机元素添加到列表中,然后将其从原始集合中移除
- 如何使用LLVM C++API向保留节点列表添加
- 是否可以使用OpenMP并行化一个列表,该列表可以在每次迭代中添加新元素
- 如何确保我的节点被添加到链接列表中
- 双链接列表添加元素不起作用,不知何故它总是保持为空
- 链接列表添加CPP
- 通过相邻顶点列表添加和减去图形中的边
- 向 C 样式可变参数列表添加额外的参数
- C ++ win 32,我想将项目列表添加到组合框中.我该怎么做
- 如何将QActions列表添加到QMenu并用单个插槽处理它们
- 将一个类的列表添加到另一个类
- 向列表添加项和迭代器问题
- C++向列表添加新的指针对象