Boost变种失败了

时间:2012-03-09 09:52:45

标签: c++ boost variant

我有这样的代码:

boost::variant<b2DistanceJointDef, b2FrictionJointDef,
       b2GearJointDef, b2MouseJointDef, b2PrismaticJointDef, b2PulleyJointDef,
       b2RevoluteJointDef, b2RopeJointDef, b2WeldJointDef, b2WheelJointDef> prmJointDef;

b2DistanceJointDef &prmDistaceJointDef = boost::get<b2DistanceJointDef>(prmJointDef);

错误是:

source\Scene\Components\JointComponent.cpp:51:96: error: no matching function for call to 'get(boost::variant<b2DistanceJointDef, b2FrictionJointDef, b2GearJointDef, b2MouseJointDef, b2PrismaticJointDef, b2PulleyJointDef, b2RevoluteJointDef, b2RopeJointDef, b2WeldJointDef, b2WheelJointDef>&)'
\source\Scene\Components\JointComponent.cpp:51:96: note: candidates are:
boost/optional/optional.hpp:626:30: note: template<class T> typename boost::optional::reference_const_type boost::get(const boost::optional<T>&)
boost/optional/optional.hpp:634:24: note: template<class T> typename boost::optional::reference_type boost::get(boost::optional<T>&)
boost/optional/optional.hpp:644:30: note: template<class T> typename boost::optional::pointer_const_type boost::get(const boost::optional<T>*)
boost/optional/optional.hpp:652:24: note: template<class T> typename boost::optional::pointer_type boost::get(boost::optional<T>*)

这里有什么问题?

1 个答案:

答案 0 :(得分:7)

Boost.Variant提供的get特定重载可通过#include <boost/variant/get.hpp>获得。

或者,boost/variant.hpp提供了大多数(如果不是全部)Boost.Variant标题,但我不建议在小玩具程序之外。细粒度的标题很不错。