2012-03-09 36 views
6

tôi có mã như:Boost biến thể lấy thất bại

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

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

Lỗi này là:

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

Whats sai ở đây?

+3

'#include ' –

+0

@LucDanton Cảm ơn, đúng vậy. – Ockonal

+1

@LucDanton bạn có thể trả lời câu hỏi này không? Tôi sẽ đánh dấu bài đăng của bạn. – Ockonal

Trả lời

7

Sự quá tải cụ thể của get mà Boost.Variant cung cấp có sẵn thông qua #include <boost/variant/get.hpp>.

Hoặc, boost/variant.hpp cung cấp hầu hết nếu không phải tất cả tiêu đề của Boost.Variant, nhưng tôi sẽ không đề xuất nó bên ngoài các chương trình đồ chơi nhỏ. Tiêu đề hạt mịn là tốt đẹp để có.

+0

Dang, tôi chỉ tìm ra điều này một cách khó khăn và tìm kiếm trên web để tìm câu hỏi mà tôi có thể trả lời;). –