I am having a hard understanding of how pointers to pointers should work, like in the following example.
let's say I have in a class in a certain file the following
typedef object* objectPtr;
and another file containing
struct RandomStruct
{
RandomStruct( objectPtr* obj = NULL ): ojbOwner( obj ) {}
objectPtr* objOwner;
}
I use both of these as members of another class and construct them like this
Constructor():
objectPtrMember( NULL )
, RandomStructMember( &objectPtr ){}
I then proceed to update my objectPtrMember
variable through an editor at runtime to point to an object, and where my logic tells me that objOwner
would be updated as well, since it points to objectPtrMember
which was updated through the editor, my editor program says otherwise as objOwner
stays NULL.
is there something I may understand wrong about pointers ? or am I just not doing the right thing ?
typedef object* objectPtr;
Avoid obfuscating pointer types like this.
NULL
NULL
shouldn't be used in new C++ programs. It exists for backward compatibility. Use nullptr
instead.
my logic tells me that objOwner would be updated as well
is there something I may understand wrong about pointers ?
Yes, there is something wrong in your understanding. Modifying one pointer will not cause another pointer to be modified.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments