Boost.Variant: Is a char * really a bool ?

When I have a Boost.Variant templated on a bool and a std::string, I get
the following behaviour ..
#include<string>
#include

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
typedef boost::variant< bool,std::string> BoostVariant;
int main () {
BoostVariant v("A String");
bool &Bref(boost::get
(v)); // this is ok std::string &Sref(boost::getstd::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.
participants (2)
-
Nindi
-
Yuval Ronen