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)。 –