I found this piece of code in the following link
http://www.tutorialspoint.com/cplusplus/cpp_copy_constructor.htm
Line::Line(const Line &obj)
{
cout << "Copy constructor allocating ptr." << endl;
ptr = new int;
*ptr = *obj.ptr; // copy the value
}
where Line is defined as:
class Line
{
public:
  int getLength( void );
  Line( int len );             // simple constructor
  Line( const Line &obj);  // copy constructor
  ~Line();                     // destructor
private:
  int *ptr;
 };
So help me understand.. What is the point in allocating memory for *ptr inside the Copy constructor ? By assigning it to *obj.ptr, essentially they are both pointing to the same locations in memory? Why should I use the new here, if it is only going to perform a shallow copy, that is copy the pointer address of the intended variable ?
 
     
    