Skip to content

Instantly share code, notes, and snippets.

@khafatech
Created April 15, 2009 06:56
Show Gist options
  • Save khafatech/95655 to your computer and use it in GitHub Desktop.
Save khafatech/95655 to your computer and use it in GitHub Desktop.
// copy constructor
Matrix::Matrix(const Matrix &rhs)
{
if (this != &rhs) {
// newly created object
this->a = NULL;
// copy rhs to this
*this = rhs;
}
}
// This actually does the copying
// If this is a new object, a is set to NULL
Matrix& Matrix::operator =(const Matrix &m)
{
if (this != &m) {
if(this->a != NULL) delete [] a;
this->x = m.x;
this->y = m.y;
this->k = m.k;
this->a = new Ratio[k];
for(int i = 0; i < k; i++)
this->a[i] = m.a[i];
}
return *this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment