
On 12/13/10 10:02, Philipp Hamann wrote:
Hi all, 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
value; void* p; value = p; bool b = boost::get<bool>(value); //OK void* p2 = boost::get (value); //Error Thanks for your help
Philipp
I think you'll have to explicitly cast the argument as shown in post:
http://article.gmane.org/gmane.comp.lib.boost.user/59167
One other option is to wrap the actual type with a tag and then
used those wrapped and tagged types as args to variant.
IOW, instead of:
variant