I have seen in some place an implementation of assignemt operator of class matrix looks like this:
class Matrix
{
private:
int rows;
int cols;
int **mat;
public:
Matrix& operator=(const Matrix& m)
{
if ( this != &m )
{
Matrix temp(m);
std::swap(temp.rows, rows);
std::swap(temp.cols, cols);
std::swap(temp.mat, mat);
}
return *this;
}
}
Now, suppose I want to use swap function for that matter , what is the alternative way to use it without writing std:swap
? Am I suppose in such case to build a friend-function that implementing swap of two matrix?