2012-03-09 74 views
6

我有這樣的代碼:升壓變得到失敗

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

請告訴我錯在這裏?

+3

'#include ' – 2012-03-09 10:03:04

+0

@LucDanton謝謝,就是這樣。 – Ockonal 2012-03-09 10:06:56

+1

@LucDanton你能回答這個問題嗎?我要標記你的帖子。 – Ockonal 2012-03-09 10:31:36

回答

7

Boost.Variant提供的get的特定超載可通過#include <boost/variant/get.hpp>獲得。

或者,boost/variant.hpp提供了大部分(如果不是全部)Boost.Variant的標題,但我不會在小玩具程序之外推薦它。細粒度的頭文件很好用。

+0

當,我剛剛發現了困難的方式,並在網上搜索了一個我可以回答的問題;)。 – 2017-05-17 16:29:55