I have an A () function that returns a pointer to an object. In function B (), I am trying to change the member of this object as follows:
void B()
{
ObjType o = *getObj();
o.set("abc");
}
The o object is stored in an array, and when I print the value of the member, nothing seems to have happened and the element still has the old value;
The solution is pretty simple:
void B()
{
ObjType * o = getObj();
o->set("abc");
}
It works. But for me this is exactly the same as the first sample. Can anyone explain this?
source
share