class SoSimple
{
int num;
public:
SoSimple (int n) : num(n)
{
cout<<"New Object: "<<this<<endl;
}
SoSimple(const SoSimple& copy) : num(copy.num)
{
cout<<"New Copy obj: "<<this<<endl;
}
~SoSimple()
{
cout<<"Destroy obj: "<<this<<endl;
}
void show()
{
cout<<num<<" and "<<this<<endl;
}
};
---------------------------
SoSimple& SimpleFuncObj(SoSimple ob)
{
ob.show();
cout<<"Parm ADR: "<<&ob<<endl;
return ob;
}
-----------------------------
SoSimple obj(7);
SoSimple tempRef=SimpleFuncObj(obj);
tempRef.show()
위에서 tempRef의 num값이 쓰레기값이 나오는데
SoSimple obj(7);
SoSimple tempRef(5);
tempRef=SimpleFuncObj(obj); //7
tempRef.show();
이거는 num값이 정상적으로 나옴
&반환형이 이해가잘안간다
위에거 왜 다르게 나오는지 설명좀 부탁
느바 믈브 느플 느흘 피시 모바일 다 생중계 고화질 버퍼없다 *사요나라오대영*