回复 9楼 zhoufeng1988
2)one2。调用带有一个int参数的构造函数,输出2。为什么调用带int参数的构造函数?
class TWO{
ONE one1;
ONE one2;
不是one2也不带参吗?
ONE(int n):c(n){cout<<2;}所以输出了2而不是1
#include<iostream> using namespace std; class ONE { public: ONE(){cout<<"1"<<endl;} }; class TWO { private: ONE a; public: TWO(){}; }; void main() { TWO a; }不要直接运行,心理想下输出结果会是几,等有了结果在运行
#include<iostream> using namespace std; class ONE { public: ONE(){cout<<"1"<<endl;} ONE(int a){cout<<"2"<<endl;} }; class TWO { private: ONE a; public: TWO(int b):a(b){}; }; void main() { TWO a(2); }步骤还是同上,慢慢的你自己会会找到为什么的