强化训练3--构造函数中调用构造(产生匿名对象)
#include<iostream>
using namespace std;
class MyTest
{
public:
MyTest(int a,int b,int c)
{
this->a = a;
this->b = b;
this->c = c;
}
MyTest(int a,int b)
{
this->a = a;
this->b = b;
MyTest(a,b,100);//构造函数里面调用了构造函数---直接调用构造函数将产生匿名对象,没有人接直接析构
}
~MyTest()
{
printf("MyTest~:%d,%d,%d\n",a,b,c);
}
protected:
private:
int a;
int b;
int c;
public:
int getC()const {return c;}
void setC(int val){c = val;}
};
int main()
{
MyTest t1(1,2);
printf("c:%d",t1.getC());//请问C的值是?
//c是个乱码,为什么??
system("pause");
return 0;
}
出现乱码的原因----内存四区图