甲构件被定义为shared_ptr的初始化
std::shared_ptr<std::array<std::string, 6> > exit_to;
指向除其他共享的附加数据。 尝试启动指针“exit_to”时。正确的方法是
node_knot.exit_to = std::make_shared<std::array<std::string, 6> >();
但它在另一个文件中,我想保持指针类型一致,这样的事情:
node_knot.exit_to = std::make_shared<decltype(*node_knot.exit_to)>();
但不会编译:
/usr/include/c++/4.6/bits/shared_ptr_base.h:798:54: error: '__p'
declared as a pointer to a reference of type
'std::array<std::basic_string<char>, 6> &'
__shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r, _Tp* __p)
^/usr/include/c++/4.6/bits/shared_ptr.h:93:31: note: in instantiation
of template class
'std::__shared_ptr<std::array<std::basic_string<char>, 6> &, 1>'
requested here
class shared_ptr : public __shared_ptr<_Tp>
^../node_booker.h:757:20: note: in
instantiation of template class
'std::shared_ptr<std::array<std::basic_string<char>, 6> &>' requested
here
n.exit_to = std::make_shared<decltype(*n.exit_to)>();
我在Ubuntu 12.10中,铿锵+ + 3.2,与--std = c + + 11
大可读性更强!我会看看remove_reference是否有用! – 2013-03-20 19:48:53