class Foo { public: explicit Foo() {} explicit Foo(Foo&) {} }; Foo d = Foo();
error: no matching function for call to \
Try without the explicit? I think that:
Foo foo = Foo()
creates an implicit copy, thus the explicit copy constructor doesn't get triggered.
Edit:
This is only half the answer. See Charles Bailey or UncleBens post for why const is necessary.