[英]Problem with initialization of vector of vector of shared_ptr class
I'm trying to initialize a vector of vector of shared_ptr class of size 19x19 ( _goban ).我正在尝试初始化大小为 19x19 ( _goban ) 的 shared_ptr class 向量的向量。
class Goban
{
public:
Goban();
~Goban();
private:
vector<vector<shared_ptr<Cell>>> _goban;
};
My constructor is like that:我的构造函数是这样的:
Goban::Goban() : _goban(18, vector<make_shared<Cell>>(18, new Cell))
{
}
I can't find the way to initialize.我找不到初始化的方法。
I got this error:我收到了这个错误:
template <class _Tp, class _Allocator /* = allocator<_Tp> */>
Any idea?任何想法?
You specified the wrong template argument make_shared<Cell>
, which should be shared_ptr<Cell>
.您指定了错误的模板参数make_shared<Cell>
,它应该是shared_ptr<Cell>
。 And note that the implicit conversion from raw pointers to std::shared_ptr
is prohibited.请注意,禁止从原始指针到std::shared_ptr
的隐式转换。 Then然后
Goban::Goban() : _goban(18, vector<shared_ptr<Cell>>(18, make_shared<Cell>()))
// ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^
{
}
With the help of deduction guide , you can even omit specifying the template argument as在演绎指南的帮助下,您甚至可以省略将模板参数指定为
Goban::Goban() : _goban(18, vector(18, make_shared<Cell>()))
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.