Transform a boost::variant into its former type

Apr 5, 2011 at 10:50am
If I have a variant variable such as

boost::variant<int, float, double, string> var

and I give to it a value...lets' suppose an int:

var = 1;

Of course I know that is an int but the compiler doesn't. So I obtain an error if I do

int a = var;

Is there a way to convert a variant variable into one of its possible types?
Apr 5, 2011 at 12:54pm
Apr 5, 2011 at 1:13pm
Yeah, it was not so difficult:

int a = boost::get<int>(var)

Thanks!
Topic archived. No new replies allowed.