On Fri, May 21, 2010 at 15:09, Robin <robin@cyberversion.com> wrote:
Hi

When I add a bool into the variant, the get int version fails (VC2008 SP1, boost
1.42.0, sorry earlier was mentioning wrong version 1.37.0)

   typedef boost::variant <bool, int, string> VariantType;

      VariantType variant;
       variant = "hello world";
       string stringTest = boost::get <string> (variant);
       cout << stringTest.c_str () << endl;

       variant = 5;
       int intTest = boost::get <int> (variant);   // Fails
       cout << intTest << endl;

When bool is added to variant, the statement
variant = "hello world" ;
calls bool constructor.

The one which is actually crashing is not int .. it is string which is crashing. because the "hello world" is not a string type strictly speaking. it is const char*. This is converted to bool and calls bool constructor.

Surya