|
Boost Users : |
Subject: Re: [Boost-users] Variant pointer and bool
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-12-13 13:35:50
AMDG
On 12/13/2010 8:02 AM, Philipp Hamann wrote:
> I have a class, call it "Property", containing a value, which can be
> of many different types, like int, string, bool, but also a pointer to
> binary data. So I decided to use boost::variant.
>
> The problem is that when I assign a pointer to the variant, it is
> implicitly casted to a bool. So I do not get the pointer out of the
> variant again.
>
> Is boost::variant not suitable for my needs or is there a recommended
> workaround?
>
> I will post some code to make my problem more clear.
>
> boost::variant<void*, bool, int, std::string> value;
> void* p;
> value = p;
> bool b = boost::get<bool>(value); //OK
> void* p2 = boost::get<void*>(value); //Error
It works fine for me with the current trunk. What version
of Boost are you using and what compiler?
In Christ,
Steven Watanabe
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