C++ Boost变量获取失败

C++ Boost变量获取失败,c++,boost,variant,C++,Boost,Variant,我有这样的代码: boost::variant<b2DistanceJointDef, b2FrictionJointDef, b2GearJointDef, b2MouseJointDef, b2PrismaticJointDef, b2PulleyJointDef, b2RevoluteJointDef, b2RopeJointDef, b2WeldJointDef, b2WheelJointDef> prmJointDef; b2DistanceJ

我有这样的代码:

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

b2DistanceJointDef &prmDistaceJointDef = boost::get<b2DistanceJointDef>(prmJointDef);
boost::variant prmJointDef;
b2DistanceJointDef&prmDistaceJointDef=boost::get(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>*)
source\Scene\Components\JointComponent.cpp:51:96:错误:对“get(boost::variant&)”的调用没有匹配的函数
\source\Scene\Components\JointComponent.cpp:51:96:注意:候选项包括:
boost/optional/optional.hpp:626:30:注意:模板typename boost::optional::reference\u const\u type boost::get(const boost::optional&)
boost/optional/optional.hpp:634:24:注意:模板typename boost::optional::reference\u type boost::get(boost::optional&)
boost/optional/optional.hpp:644:30:注意:模板typename boost::optional::pointer\u const\u type boost::get(const boost::optional*)
boost/optional/optional.hpp:652:24:注意:模板typename boost::optional::pointer_type boost::get(boost::optional*)

这里出了什么问题?

Boost.Variant提供的
get
的特定重载可通过
\include
获得


或者,
boost/variant.hpp
提供了boost.variant的大部分(如果不是全部的话)头文件,但我不建议在小型玩具程序之外使用它。细粒度的头文件很好。

#include
@LucDanton谢谢,就这样。@LucDanton你能回答这个问题吗?我会在你的帖子上做标记。该死,我只是想方设法找到了答案,然后在网上搜索了一个我能回答的问题;)。