What is the effect of 'explicit' keyword on the Return Value Optimization (RVO)?
问题 Following code works perfectly fine (showing RVO): struct A { A (int) { cout << "A::A()\n"; } // constructor A (const A&) { cout << "A::A(const A&)\n"; } // copy constructor }; A foo () { return A(0); } int main () { A a = foo(); } Output: A::A() // --> which means copy constructor is not called If I mark the copy constructor as explicit : explicit A (const A&) { ... } Then the compiler errors out: explicit.cpp: In function ‘A foo()’: explicit.cpp:10:22: error: no matching function for call