title: Copy constructor and dynamically allocated array
body: <p>I will keep it short and clear - in order to practise dynamically allocated memory, I decided to make a circle in which I will store it's parameters (X and Y of the center and radius length) in a dynamically allocated array. Since the array is dynamically allocated this means that in order to stop a leak I have to implement a constructor. It also means that in order to avoid a couple of other bugs I need to implement a copy constructor and overload the assignment operator. (with pretty much the same code) I think I have implemented the destructor reasonably well. I do need a bit of help with the copy constructor, though.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class Circle
  {
  private:
      int* data;
  public:
      Circle(){
          cout &lt;&lt;"I am the default constructor" &lt;&lt; endl;
          data = NULL;
      }
      Circle(int* p){
          cout &lt;&lt;"I am the set up constructor" &lt;&lt; endl;
          data = p;
      }
      ~Circle(){
          cout &lt;&lt;"I am the destructor" &lt;&lt; endl;
          delete data;
      }
      Circle&amp; operator=(const Circle&amp; tt1){
          cout &lt;&lt; "Overloaded assignment operator reporting in!" &lt;&lt; endl;
          if(this != &amp;tt1){
              //free old data
              delete this-&gt;data;
              data = new int(3);
             *data = *(tt1.get_data());
              *(arr+1) = *(tt1-&gt;get_data()+1);
              *(arr+2) = *(tt1-&gt;get_data()+2);
              return *this;
          }
      }
      Circle(const Circle&amp; tt1){
          cout &lt;&lt; "I am the copy constructor!" &lt;&lt; endl;
          if(this != &amp;tt1){
              //free old data
              delete this-&gt;data;
              data = new int(3);
             *data = *(tt1.get_data());
              *(arr+1) = *(tt1-&gt;get_data()+1);
              *(arr+2) = *(tt1-&gt;get_data()+2);
              return *this;
          }
      }
  };
  
  int main(){
      //is this object constructed well?
      int arr [] = { 16, 2, 7};
      Circle a(arr);
  
      return 0;
  }
  </code></pre>