It's important to make a distinction between:
1. "Pointer" as a variable residing on the stack. The name tempb refers to one such variable.
2. "Pointer" as an integer value that refers to a memory location. The variable tempb refers to holds such a value.
One should delete every newed pointer of the second meaning. This is incorrect:
foo and bar hold the same pointer. Deleting them both deletes the same pointer twice.
This is why the concept of pointer ownership is also important. An object is said to own a pointer if it assumes the responsibility of freeing it. Pointer ownership is implicitly implemented in the way you structure your code. For example, here:
foo transfers the ownership of its pointer to bar, and here:
1. "Pointer" as a variable residing on the stack. The name tempb refers to one such variable.
2. "Pointer" as an integer value that refers to a memory location. The variable tempb refers to holds such a value.
One should delete every newed pointer of the second meaning. This is incorrect:
| |
This is why the concept of pointer ownership is also important. An object is said to own a pointer if it assumes the responsibility of freeing it. Pointer ownership is implicitly implemented in the way you structure your code. For example, here:
| |
| |
the pointer is copied without ownership transfer.
There is obvisouly distinction i should know more. What' s the pointer ownership?