Why is there an implicit type conversion from pointers to bool in C++?
问题 Consider the class foo with two constructors defined like this: class foo { public: foo(const std::string& filename) {std::cout << "ctor 1" << std::endl;} foo(const bool some_flag = false) {std::cout << "ctor 2" << std::endl;} }; Instantiate the class with a string literal, and guess which constructor is called? foo a ("/path/to/file"); Output: ctor 2 I don't know about you, but I don't find that the most intuitive behavior in programming history. I bet there is some clever reason for it,