3

In the example below:

boost::variant<double, std::string, bool> testString("this string");
std::string s1 = boost::get<std::string>(testString);

We will fail with a runtime exception:

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

Upon investigation the which value of the variant:

std::cout << testString.which() << "\n";

It is value of 2 so it is clearly matching to the bool during construction. This is further confirmed by the fact that this works correctly:

boost::variant<double, std::string> testString("this string"); // bool is removed

Why is boost variant matching the "this string" in construction to the bool instead of the string?

Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175

0 Answers0