Pointer pointing at Pointer
Say X points to an object of type Z, Z* X = new Z; , and A points to X, would it be correct to assume A holds the address of pointer X. In that case would 'delete A' delete the object pointed to by X or would it simply remove the address stored in A. Or would I have to say 'delete(*A)' to delete the object pointed to by X.
I would be very grateful for all help.
[396 byte] By [
ray] at [2007-11-11 8:48:16]

# 1 Re: Pointer pointing at Pointer
Yes, A in that case contains the address of X. So you need to use delete *A; to delete the object Z.
If A was declared like this:
A ** Z = &X;
You can't call delete A; as this would cause undefined behavior and will not release the object to which X points.
Danny at 2007-11-11 21:01:06 >
