问题1:如果 被嵌入的类(class A) 中没有能够初始化的构造函数,请问该怎么给该类的对象进行初始化?
问题2:为什么 A a(int)
没有报错?到底有没有调用A类的构造函数?
供参考:
#include<iostream>
using namespace std;
class A{
private :
int x;
public :
A(int y):x(y){
cout<< "class A"<< endl;
}
int get_A(){return x;}
};
class B{
private :
A a;
public :
B():a(0){cout<< "class B" <<endl;}
A get_B(){return a;}
};
int main()
{
B b;
cout<< b.get_B().get_A()<<endl;
system("pause");
return 0;
}