【发布时间】:2015-01-13 11:38:52
【问题描述】:
我正在尝试对我的 Matrix 类中的 * 运算符进行重载。
如果它是 Matrix*something, (int, double...),我有一个可以做到的
我正在寻找一个适合另一面的东西,即某物*矩阵
这是我尝试过的
template<class T>
bool operator*(Matrix<T>& other ){
Matrix<T> mat(other.rows,other.columns);
for(int i=0;i<other.rows;i++){
for(int j=0;j<other.columns;j++){
T temp=other.get(i,j);
temp=temp*(this);
mat.set(i,j,temp);
}
}
return mat;
}
这就是 Matrix*something 的作用
Matrix<T>& operator*(const T & num){
Matrix<T> mat(rows,columns);
for(int i=0;i<rows;i++){
for(int j=0;j<columns;j++){
T temp=(matrix[i][j]);
temp=temp*num;
mat.set(i,j,temp);
}
}
return mat;
}
【问题讨论】:
标签: c++ templates matrix overloading operator-keyword