#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);//由于调用构造函数结果没有接出来,相当于匿名对象,还没传出来就被析构了(生命周期短),最后对c的赋值也相对于没有了。调用失败
printf("c:%d", t1.getC()); //请问c的值是?
system("pause");
return 0;
}
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);//由于调用构造函数结果没有接出来,相当于匿名对象,还没传出来就被析构了(生命周期短),最后对c的赋值也相对于没有了。调用失败
printf("c:%d", t1.getC()); //请问c的值是?
system("pause");
return 0;
}