当一个类拥有一个类成员,会先根据定义顺序对类成员进行构造,然后再构造自己。
class Test206191
{
public:
Test206191()
{
cout << "construct 6191" << endl;
}
};
class Test20619
{
public:
Test20619()
{
cout << "construct 619" << endl;
}
private:
Test206191 _test206191;
};
int main()
{
Test20619 test;
return 0;
}
输出:
construct 6191
construct 619
参考资料:
https://www.cnblogs.com/ayanmw/p/4702044.html
https://blog.csdn.net/weixin_33840661/article/details/86002750