class OBJ
{
public:
OBJ(int n):a(n){cout<<"ctor"<<'\n'; }
~OBJ(){ cout<<"dctor"<<'\n';}
int geta(){ return a;}
protected:
private:
int a;
};
OBJ * getobj( )
{
OBJ *p=new OBJ(10);
return p;
}
note the function getobj, in this fuction, new allocates memory that is pointed by p, but in this function, p can't be deleted. That may cause memory leak? How to avoid this?