ThisClass *p = hoge;
hoge = NULL;
if(p!=this)
{delete p;
return this;
}else{return p;}
こんな感じか