title: c++ constructor with new
body: <p>I'm making a very dumb mistake just wrapping a pointer to some new'ed memory in a simple class.</p>
  
  <pre><code>class Matrix
  {
    public:
      Matrix(int w,int h) : width(w),height(h)
      {           
          data = new unsigned char[width*height];
      }
  
      ~Matrix() { delete data;    }
  
      Matrix&amp; Matrix::operator=(const Matrix&amp;p)
      {  
              width = p.width;
              height = p.height;
              data= p.data;
              return *this;
      }
      int width,height;
      unsigned char *data;
  }
  
  .........
  // main code
  std::vector&lt;Matrix&gt; some_data;
  
  for (int i=0;i&lt;N;i++) {
     some_data.push_back(Matrix(100,100)); // all Matrix.data pointers are the same
  }
  </code></pre>
  
  <p>When I fill the vector with instances of the class, the internal data pointers all end up pointing to the same memory ?</p>