Z
Zenon
Folks,
I have been trying for a week but I cannot debug the following error:
Error E2285 ex5.cpp 141: Could not find a match for
'matrix<complex<double>>:perator =(complex<double>)' in function
main()
Here is the relevant portion of my template class
//***************************************************************************
#include <iostream>
#include <string>
#include <vector>
template <class Type>
class matrix
{
private:
std::vector<matrix<Type> > _data ;
int _nrows ;
int _ncols ;
public:
matrix<Type> (int rows=1, int cols=1) ;
matrix<Type> (const matrix<Type>& rhs) ;
~matrix<Type> () {};
matrix<Type>& operator=(const matrix<Type>& rhs) ;
matrix<Type>& lookup (int row, int col) ;
const matrix<Type>& lookup (int row, int col) const ;
matrix<Type>& operator() (int row, int col)
{
return lookup (row, col) ;
}
const matrix<Type>& operator() (int row, int col) const
{
return lookup (row, col) ;
}
int rows () const
{
return _nrows ;
}
int cols () const
{
return _ncols ;
}
} ; // end matrix
//*****************************************************************************
// Matrix constructor implementation
template <class Type>
matrix<Type>::matrix (int rows, int cols)
: _data (rows * cols), _nrows (rows), _ncols (cols)
{ }
template <class Type>
matrix<Type>::matrix (const matrix<Type>& rhs)
: _data (rhs._data), _nrows(rhs._nrows), _ncols(rhs._ncols)
{ }
// Matrix operator= implementation
template <class Type>
matrix<Type>& matrix<Type>:perator= (const matrix<Type>& rhs)
{
if (this != &rhs)
{
_data = rhs. _data ;
_nrows = rhs. _nrows ;
_ncols = rhs. _ncols ;
}
return *this ;
}
template <class Type>
matrix<Type>& matrix<Type>::lookup (int row, int col)
{
int linear_index = row * _ncols + col ;
return _data [linear_index] ;
}
template <class Type>
const matrix<Type>& matrix<Type>::lookup (int row, int col) const
{
int linear_index = row * _ncols + col ;
return _data [linear_index] ;
}
//****************************************************************************
And here is the calling code:
matrix<complex<double> > Y (2, 2) ;
Y (0, 0) = complex<double> (300.0, 1) ;
What am I doing wrong? Can anyone please help?
Thank you very much,
Zenon
I have been trying for a week but I cannot debug the following error:
Error E2285 ex5.cpp 141: Could not find a match for
'matrix<complex<double>>:perator =(complex<double>)' in function
main()
Here is the relevant portion of my template class
//***************************************************************************
#include <iostream>
#include <string>
#include <vector>
template <class Type>
class matrix
{
private:
std::vector<matrix<Type> > _data ;
int _nrows ;
int _ncols ;
public:
matrix<Type> (int rows=1, int cols=1) ;
matrix<Type> (const matrix<Type>& rhs) ;
~matrix<Type> () {};
matrix<Type>& operator=(const matrix<Type>& rhs) ;
matrix<Type>& lookup (int row, int col) ;
const matrix<Type>& lookup (int row, int col) const ;
matrix<Type>& operator() (int row, int col)
{
return lookup (row, col) ;
}
const matrix<Type>& operator() (int row, int col) const
{
return lookup (row, col) ;
}
int rows () const
{
return _nrows ;
}
int cols () const
{
return _ncols ;
}
} ; // end matrix
//*****************************************************************************
// Matrix constructor implementation
template <class Type>
matrix<Type>::matrix (int rows, int cols)
: _data (rows * cols), _nrows (rows), _ncols (cols)
{ }
template <class Type>
matrix<Type>::matrix (const matrix<Type>& rhs)
: _data (rhs._data), _nrows(rhs._nrows), _ncols(rhs._ncols)
{ }
// Matrix operator= implementation
template <class Type>
matrix<Type>& matrix<Type>:perator= (const matrix<Type>& rhs)
{
if (this != &rhs)
{
_data = rhs. _data ;
_nrows = rhs. _nrows ;
_ncols = rhs. _ncols ;
}
return *this ;
}
template <class Type>
matrix<Type>& matrix<Type>::lookup (int row, int col)
{
int linear_index = row * _ncols + col ;
return _data [linear_index] ;
}
template <class Type>
const matrix<Type>& matrix<Type>::lookup (int row, int col) const
{
int linear_index = row * _ncols + col ;
return _data [linear_index] ;
}
//****************************************************************************
And here is the calling code:
matrix<complex<double> > Y (2, 2) ;
Y (0, 0) = complex<double> (300.0, 1) ;
What am I doing wrong? Can anyone please help?
Thank you very much,
Zenon