http://baike.baidu.com/view/1266959.htm
http://blog.csdn.net/fornormandy/article/details/79512
#include <iostream> #include <stdio.h> using namespace std; class C { public: int i; //explicit C(const C& arg):i(10) C(const C& arg) // an explicit copy constructor { i = 10; printf("in the copy constructor\n"); } explicit C(int i ) // an explicit constructor { printf("\nin the constructor"); } C() { i = 0; } }; C f(C c) { // C2558 c.i = 2; printf("%d\n",c.i); return c; // first call to copy constructor } int main() { C c; c = f(c); // c is copied 临时拷贝 printf("%d\n",c.i); }
explicit关键字禁止隐式转换、禁止拷贝构造