c++自动回收的问题,对象从子函数返回后还能生效
#include "stdafx.h"#include <iostream>using namespace std;class A{ int v; char* name;public: A(char* n){ this->name = n; v=3; cout << name << "-->create " << endl; } ~A(){ cout << name << "-->Destroy " << endl; } void setValue(int v){ this->v =v; } int getValue(){ return v; }}; A getA(){ A a("getA()") ;//= new A("getA()"); a.setValue(1999); A* b =&a; return a;}int _tmain(int argc, _TCHAR* argv[]){ A c = getA(); A *d =(&c); c.setValue(6000); cout << "c.getValue:" << c.getValue() << endl; //这里正常 delete d; //这里就出错了 return 0; }