我想在我的构造函数中初始化一个 bool vector 的 vector 。
这是我的课:
class MyClass{
public:
MyClass(const OtherClass&g):
g(g), count(g.node_count(), std::vector<bool>(16))){}
private:
const OtherClass&g;
std::vector<std::vector<bool>>count;
};
但是当我尝试初始化 count
时,我得到了这个错误:
error: no match for call to ‘(std::vector<std::vector<bool> >) (int)’
最佳答案
您想使用 fill constructor .如果您不使用 C++ 11,则需要为 vector 中的元素指定默认值 count(g.node_count(), std::vector<bool>(16, true))
关于c++ - 初始化 vector 的 vector 的类构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40997774/