0

鉴于:

typedef boost::variant<std::vector<int8>, std::vector<std::string> > Container;

如何初始化c为单列?

std::vector<std::string> v = boost::assign::list_of<std::string>("stringValue");
Container c(v);
4

1 回答 1

1

应该这样做 - 将 list_of 结果显式转换为您希望变体存储的类型:

Container c(vector<string>(list_of<string>("stringValue")));

甚至更好 - 使用 C++11:

Container c{ vector<string> {"stringValue1", "stringValue2"}};
于 2013-01-28T14:31:22.653 回答