有我的课的矩阵操作的一部分:C++,矩阵运算,与运营商的问题
class Matrix
{
private:
std::vector < std::vector <T> > items;
const unsigned int rows_count;
const unsigned int columns_count;
public:
Matrix (unsigned int m_rows, unsigned int m_columns);
Matrix (const Matrix <T> &M);
template <typename U>
Matrix <T> & operator = (const Matrix <U> &M);
template <typename U>
bool operator == (const Matrix <U> &M) const;
template <typename U>
bool operator != (const Matrix <U> &M) const ;
template <typename U>
Matrix <T> operator + (const Matrix <U> &M) const
...
};
其中
template <typename T>
template <typename U>
Matrix <U> Matrix <T> ::operator + (const Matrix <U> &M) const
{
Matrix <U> C (M);
for (unsigned int i = 0; i < rows_count; i++)
{
for (unsigned int j = 0; j < M.getColumnsCount(); j++)
{
C (i, j) = items[i][j] + M.items[i][j];
}
}
return C;
}
template<class T>
Matrix <T> :: Matrix (const Matrix <T> &M)
: rows_count (M.rows_count), columns_count (M.columns_count), items (M.items) {}
但与以下运营商的一个问题:=
,==
,!=
我想分配矩阵A
Matrix <double> A (2,2);
Matrix <double> C (2,2);
到矩阵B
Matrix <int> B (2,2);
B = A; //Compiler error, see bellow, please
其中A和B具有不同的类型。同样的情况发生,共同矩阵运算
C = A + B //Compiler error, see bellow, please
但是编译器显示此错误:
Error 23 error C2446: '!=' : no conversion from 'const Matrix<T> *' to 'Matrix<T> *const '
感谢您的帮助......
你实际上并没有发布实施,任何能产生一个错误的功能。 – Puppy 2011-04-25 19:54:53
@DeadMG:运营商+代码中存在拼写错误,我纠正了它... – Robo 2011-04-25 19:59:22
错误消息引用的指针完全缺少您提供的代码。注意'const Matrix *'相当于'Matrix const *'而不是'Matrix * const'。 –
AProgrammer
2011-04-25 20:01:57