Pointers do not create dynamic memory allocation. Pointers and distributions are completely different things.
If you copy a pointer that points to dynamically allocated memory, you have two pointers that point to the same allocated memory. Since you copied it, it already points to a block of memory. In particular, if you use the copy constructor created by the compiler, the new pointer will point to the same as the old pointer. You do not need to do anything about it if this is normal.
You have a problem when you need to free memory. Freeing it twice will usually cause cumulus damage, which is unpleasant. Without freeing it, this will lead to a memory leak, which may be acceptable in some cases. Freeing it before another pointer fires will also cause problems. For this reason, people who have several pointers to the same memory often go to the Boost project and use their shared_ptr template (which will be in the new new standard and present in most modern systems).
If you want each pointer to point to separate pieces of memory, you must set this by writing your own copy constructor and selecting a new piece and copying the necessary data into it. (You also need to write your own assignment operator for the same reasons and your own destructor so you can free up memory. There, a rule of thumb called Rule three says that if you need to write your own copy of a constructor, assignment operator or destructor, you you probably need to write all of them.)
David thornley
source share