Explicit constructor without a single parameter

Can someone explain why a constructor without a single parameter is marked as an explicit compiler? As far as I understand, this is an absolutely useless keyword here, so why does it compile without errors?

class X { public: explicit X(int a, int b) { /* ... */} }; 
+7
c ++ constructor explicit-constructor
source share
2 answers

In C ++ 03, and in this particular case, it makes no sense to highlight two explicit parameter constructors. But this may make sense here:

 explicit X(int i, int j=42); 

So, marking two parameter constructors with explicit should not be an error.

In C ++ 11, this use of explicit is not allowed for you:

 X x = {1,2}; 
+10
source share

Not quite right.

In C ++ 11, constructors with multiple arguments can be implicitly converted using parenthesis initialization.

+6
source share

All Articles