using namespace std; class A { public: A() { cout << "默认无参构造函数" << endl; } #if 0 explicit A(int a) { cout << "显示构造函数" << endl; //只要参数只有1个的构造函数【包括拷贝构造函数】,就可以在前面加explicit,代表不能直接将参数赋值【等号】给A对象 } #endif A(int a) { cout << "类型转换构造函数" << endl;//参数只有1个且类型与类不同,默认是可隐式赋值【等号】,即implicit【不是C++关键字】 this->a = a; } A(double b, int a = 0) { cout << "类型转换构造函数" << endl;//a有默认值,所以也算参数只有1个且类型与类不同 this->a = a; this->b = b; } A(const A& a) { cout << "拷贝构造函数" << endl; this->a = a.a; } A &operator = (const A &a) { cout << "运算符重载构造函数" << endl; this->a = a.a; return *this; } private: int a; double b; }; int main() { A a; A b(a); A c = 1; A d = a;//拷贝构造函数 A e;e = a; getchar(); return 0; }