我想了解boost遞歸變體和模板。對於下面的代碼,我得到的Boost遞歸變體以及模板C++
cannot convert argument 1 from 'std::vector<std::string,std::allocator<_Ty>>' to 'const Boost::variant<boost::detail::variant::recursive_flag<T0>,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19> &'
錯誤似乎是從GetVarValue()
功能
按我undertanding我可以有_default一類起源編譯錯誤:它可以是int的載體,字符串,布爾,雙,向量的整數/字符串/布爾/雙右?
typedef boost::make_recursive_variant<
int,
std::string,
bool,
double,
std::vector<boost::recursive_variant_> >::type TokenValueType;
template<class T>
class VectorToken : public Token
{
private:
string _name;
vector<T> _default;
public:
VectorToken(string name, vector<T> defaultVal)
: _name(name)
{
_default = defaultVal;
}
virtual TokenValueType GetVarValue()
{
return _default; <-- _default (vector<string>) doesn't like TokenValueType ?
}
};
main()
{
vector<string> tempvec = {"ABC", "LMN", "PQR"};
VectorToken<string> t4 = VectorToken<string>::VectorToken("VECTORSTR", tempvec);
}
錯誤消失時,我寫的主要是這樣的:
main()
{
vector<TokenValueType> tempvec = { string("ABC"), string("LMN"), string("PQR") };
VectorToken<TokenValueType> t4 = VectorToken<TokenValueType>::VectorToken("VECTORSTR", tempvec);
}