
explicit Keyword 2/2
struct A {
A() {}
A(int) {}
A(int, int) {}
};
void f(const A&) {}
A a1 = {}; // ok
A a2(2); // ok
A a3 = 1; // ok (implicit)
A a4{4, 5}; // ok. Selected A(int, int)
A a5 = {4, 5}; // ok. Selected A(int, int)
f({}); // ok
f(1); // ok
f({1}); // ok
struct B {
explicit B() {}
explicit B(int) {}
explicit B(int, int) {}
};
void f(const B&) {}
// B b1 = {}; // error implicit conversion
B b2(2); // ok
// B b3 = 1; // error implicit conversion
B b4{4, 5}; // ok. Selected B(int, int)
// B b5 = {4, 5}; // error implicit conversion
B b6 = (B) 1; // OK: explicit cast
// f({}); // error implicit conversion
// f(1); // error implicit conversion
// f({1}); // error implicit conversion
f(B{1}); // ok
36/68