|
Boost Users : |
From: David Klein (dave_chp_at_[hidden])
Date: 2007-05-09 18:08:50
Jeffrey Holle wrote:
> After much inefficient debugging, I've discovered that adding a pointer
> type to a boost::variant is a no-no. It appears to get translated into
> a bool via get<>, which throws a bad_get exception erroneously (at least
> in my opinion).
>
> The caviots of using a pointer type in variant really needs to be
> documented! It doesn't appear to be done so now.
>
> I've discovered that wrapping the pointer in a boost::shared_pointer is
> a solution. But it wasn't obvious.
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
Hi Jeffrey,
f.ex:
variant<int *, double *> v;
int i = 12345;
v = &i;
cout << *get<int *>(v) << endl;
double d = 1.2345;
v = &d;
cout << *get<double *>(v) << endl;
cout << *get<int *>(v) << endl;
output is:
12345
1.2345
*exception*
Thats exactly what I would expect. Am I missing something?
(tested with boost_1_34_beta + gcc 3.4.2)
-- Regards, dave
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net