In writing a copy constructor for a class that holds a pointer to dynamically allocated memory, I have a question.
How can I specify that I want the value of the pointer
You allocate new object
class Foo { Foo(const Foo& other) { // deep copy p = new int(*other.p); // shallow copy (they both point to same object) p = other.p; } private: int* p; };