boost::variant apply static_visitor to certain types
问题 I have the following variant: typedef boost::variant<int, float, bool> TypeVariant; And I want to create a visitor to convert a int or float type to a bool type. struct ConvertToBool : public boost::static_visitor<TypeVariant> { TypeVariant operator()(int a) const { return (bool)a; } TypeVariant operator()(float a) const { return (bool)a; } }; However this is giving me the error message: 'TypeVariant ConvertToBool::operator ()(float) const': cannot convert argument 1 from 'T' to 'float' What