fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. struct Foo
  5. {
  6. Foo& operator= (bool value) {std::cout << "bool\n"; return *this;}
  7. Foo& operator= (const std::string& value) {std::cout << "string\n"; return *this;}
  8. };
  9.  
  10. int main() {
  11. Foo foo;
  12. foo = true; // works...assigned as bool
  13. foo = "i_am_a_string"; // SURPRISE...assigned as bool, not string
  14. std::string s = "i_am_a_string";
  15. foo = s; // works...assigned as string
  16. foo = static_cast<std::string>("i_am_a_string"); // works...but awkward
  17. }
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
bool
bool
string
string