.:: Blackc0de Forum ::.
Would you like to react to this message? Create an account in a few clicks or log in to continue.

-=Explore The World From Our Binary=-
 
HomeIndeksLatest imagesPendaftaranLogin

 

 c++ assignment operator implementation in templated class

Go down 
PengirimMessage
Jiban
Corporal
Corporal
Jiban


Jumlah posting : 159
Points : 390
Reputation : 7
Join date : 09.07.11

c++ assignment operator implementation in templated class Empty
PostSubyek: c++ assignment operator implementation in templated class   c++ assignment operator implementation in templated class Icon_minitimeTue Mar 20, 2012 6:28 pm

Matrix<float,3,4> mat1;
Matrix<int,45,45> mat2;
mat1 = mat2;

/Users/Jake/Dropbox/C++/test.cpp: In function ‘bool test1()’:
/Users/Jake/Dropbox/C++/test.cpp:23: error: no match for ‘operator=’ in ‘m2 = m1’
/Users/Jake/Dropbox/C++/Matrix.h:22: note: candidates are: Matrix<float, 3u, 4u>& Matrix<float, 3u, 4u>::operator=(const Matrix<float, 3u, 4u>&)

template <class T, unsigned int rows, unsigned int cols>
template <class T2, unsigned int rows2, unsigned int cols2>
Matrix<T, rows2, cols2> & Matrix<T,rows,cols>::operator= (const Matrix<T2, rows2, cols2> & second_matrix){
unsigned int i,j;
for (i=0; i < rows2; i++){
for (j=0; j < cols2; j++){
data[i][j] = second_matrix(i,j);
}
}
this->_rows = rows2;
this->_cols = cols2;
return *this;
}

Matrix<float,3,4> mat1;
Matrix<int,45,45> mat2;
mat1 = mat2;

template <class T>
class Matrix
{
unsigned int rows;
unsigned int cols;
public:
Matrix(numrows, numcols): rows(numrows), cols(numcols) {}
};

class MatrixBase { };

template <typename T, unsigned Rows, unsigned Columns>
class Matrix : public MatrixBase { };
Kembali Ke Atas Go down
 
c++ assignment operator implementation in templated class
Kembali Ke Atas 
Halaman 1 dari 1

Permissions in this forum:Anda tidak dapat menjawab topik
.:: Blackc0de Forum ::. :: BoarD Blackc0de :: International Room :: Programming (Int.) :: Command Line-
Navigasi: