考察以下两段代码区别
class Test {
public:
Test() {
};
Test(int x) {
this->int_x = x;
};
void show() { cout << int_x << endl; }
private:
int int_x;
};
class Mytest :public Test {
public:
Mytest()
{
Test(110);
}; //情况1 输出-842150451 Test(110)是一个临时对象
Mytest() :Test(110) {} //情况2 输出110 正常理解即可
};
int main()
{
Test *p = new Mytest();
p->show();
return 0;
}