【问题标题】:Boost variant get failBoost变体失败
【发布时间】:2012-03-26 18:47:08
【问题描述】:

我有这样的代码:

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>*)

这里有什么问题?

【问题讨论】:

  • #include &lt;boost/variant/get.hpp&gt;
  • @LucDanton 谢谢,就是这样。
  • @LucDanton 你能回答这个问题吗?我会标记你的帖子。

标签: c++ boost variant


【解决方案1】:

Boost.Variant 提供的get 的特定重载可通过#include &lt;boost/variant/get.hpp&gt; 获得。

另外,boost/variant.hpp 提供了 Boost.Variant 的大部分(如果不是全部)标头,但我不建议在小型玩具程序之外使用它。细粒度的标头很不错。

【讨论】:

  • 该死,我只是想通了这一点,并在网上搜索了一个我可以回答的问题;)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多