Boost variant get fail
Asked Answered
P

1

6

I have such code:

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

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

The error is:

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 wrong here?

Pitchman answered 9/3, 2012 at 9:52 Comment(2)
#include <boost/variant/get.hpp>Adopt
@LucDanton could you answer the question? I gonna mark yours post.Pitchman
A
8

The particular overload of get that Boost.Variant provides is available through #include <boost/variant/get.hpp>.

Alternatively, boost/variant.hpp provides most if not all of the headers of Boost.Variant, but I wouldn't recommend it outside of small toy programs. Fine-grained headers are nice to have.

Adopt answered 9/3, 2012 at 10:45 Comment(1)
Dang, I just figured this out the hard way and searched the web to find a question that I could answer ;).Fornix

© 2022 - 2024 — McMap. All rights reserved.