Boost logo

Boost Users :

From: Nindi Singh (nindi73_at_[hidden])
Date: 2006-07-01 12:53:40


I sort of guessed that this implicit conversion was taking place ... but unfortunatley it wil make my variant very error prone .. and on the other hand I do want the capability to construct from a C string appropriatley. I think one possible soultion would be to derive from boost::variant<bool,std::string> and put in an explicit constructor for const char *, this will also let me get around other similar problems. However deriving from boost::variant .... ???
not sure how healthy that is.
 
 
 
>To answer the question in the subject line: char* isn't bool, but it's
>implicitly convertible to bool, which is probably (haven't really
>checked, just an educated guess) what's causing you trouble.
>
>Nindi wrote:
>> When I have a Boost.Variant templated on a bool and a std::string, I get
>> the following behaviour ..
>>
>> #include<string>
>>
>> #include<boost/variant.hpp>
.>
>> typedef boost::variant< bool,std::string> BoostVariant;
>>
>> int main () {
>>
>> BoostVariant v("A String");
>>
>> bool &Bref(boost::get<bool&>(v)); // this is ok
>>
>> std::string &Sref(boost::get<std::string&>(v)); // But this throws
>>
>> return 0;
>>
>> }
>
>Instead of
> BoostVariant v("A String");
>try
> BoostVariant v(std::string("A String"));
>
>I think it will solve your problems.


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