Overloaded constructor - a constructor with a bool argument takes precedence

I recently came across a class like

class Foo {
public:
    Foo(std::string msg) {}
private:
    Foo(bool b) {}
};

I noticed that trying to create an object of this class with

Foo foo("blah");

causes a compilation error indicating that it Foo::Foo(bool)is closed. Apparently, if the argument is not the actual std :: string, the compiler prefers to use the constructor with the argument bool. On the other hand, if no private constructor is specified, the code above the code is just fine.

Why booldoes " string-constructor" take precedence over " -constructor" althogh, the type of argument passed does not fit any of them? Is it just a matter of definition or has a deeper meaning and good reason?

+5
source
1

.

  • std::string
  • bool

# 1 - , # 2 - /. , , , .

Edit

,

++

+7

All Articles