本文共 564 字,大约阅读时间需要 1 分钟。
具体看如下代码:
#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, 1000); //产生新的匿名对象,匿名对象销毁时,也会调用析构函数 } ~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;}/**输出:MyTest : 1,2,1000c:-858993460 */
转载地址:http://aezmi.baihongyu.com/