Why is explicit allowed for default constructors and constructors with 2 or more (non-default) parameters?

One reason certainly is because it doesn’t hurt. One reason where it’s needed is, if you have default arguments for the first parameter. The constructor becomes a default constructor, but can still be used as converting constructor struct A { explicit A(int = 0); // added it to a default constructor }; C++0x makes actual … Read more

What could go wrong if copy-list-initialization allowed explicit constructors?

Conceptually copy-list-initialization is the conversion of a compound value to a destination type. The paper that proposed wording and explained rationale already considered the term “copy” in “copy list initialization” unfortunate, since it doesn’t really convey the actual rationale behind it. But it is kept for compatibility with existing wording. A {10, 20} pair/tuple value … Read more

C++ always use explicit constructor [closed]

The traditional wisdom is that constructors taking one parameter (explicitly or effectively through the use of default parameters) should be marked explicit, unless they do define a conversion (std::string being convertible from const char* being one example of the latter). You’ve figured out the reasons yourself, in that implicit conversions can indeed make life harder … Read more

Explicit constructor taking multiple arguments

Up until C++11, yeah, no reason to use explicit on a multi-arg constructor. That changes in C++11, because of initializer lists. Basically, copy-initialization (but not direct initialization) with an initializer list requires that the constructor not be marked explicit. Example: struct Foo { Foo(int, int); }; struct Bar { explicit Bar(int, int); }; Foo f1(1, … Read more