Why is it legal in C++ to call a constructor of a primitive type?

Although bool is a primitive type, and as such has no constructor, language designers introduced unified initialization syntax that works for primitives as well as for classes. This greatly simplifies writing template code, because you can continue using the

T tVar(initialVal);

syntax without knowing if T, a template type parameter, is primitive or not. This is a very significant benefit to template designers, because they no longer need to think about template type parameters in terms of primitive vs. classes.


That is just a valid syntax to initialize POD types and have a similar behavior to a constructor (or even a copy constructor for that matter).

For example, the following would be valid:

bool a(false);
bool b(a);
bool c = bool(); // initializes to false

One interesting thing to note is that in

int main(int argc, const char *argv[])
{
  bool f();
  return 0;
}

f is a function declaration!