std::vector<int> value = boost::assign::list_of(1)(2);
但不是这样的:
Constructor(std::vector<int> value)
{
}
Constructor (boost::assign::list_of(1)(2));
是否有初始化传递给构造矢量一行代码的解决方案?
更妙的是,如果构造复制到一个类变量,采取了参考,而不是:
Constructor(std::vector<int>& value)
{
_value = value;
}
UPDATE
如果我尝试以下方法:
enum Foo
{
FOO_ONE, FOO_TWO
};
class Constructor
{
public:
Constructor(const std::vector<Foo>& value){}
};
Constructor c(std::vector<Foo>(boost::assign::list_of(FOO_ONE)));
我得到编译器错误:
error C2440: '<function-style-cast>' : cannot convert from 'boost::assign_detail::generic_list<T>' to 'std::vector<_Ty>'
1> with
1> [
1> T=Foo
1> ]
1> and
1> [
1> _Ty=Foo
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
你可以给编译器错误信息吗? –
@Kevin MOLCARD添加编译器错误 – Baz
[看起来像这是错误](https://svn.boost.org/trac/boost/ticket/7364)。 –