【发布时间】:2016-10-08 09:34:58
【问题描述】:
我正在为一个 OpenGLES 项目编写数学模块。 我写了一个类来管理通用大小的浮点矩阵
template <unsigned int N>
class MatrixN {
public:
float m[N*N];
MatrixN(){}
virtual ~MatrixN(){}
void identify();
MatrixN& operator=(const MatrixN& b);
};
template <unsigned int N>
MatrixN<N> operator*(const MatrixN<N>& a, const MatrixN<N>& b);
//CPP file implementation
template<unsigned int N>
MatrixN<N> operator*(const MatrixN<N>&a, const MatrixN<N> &b) {
MatrixN<N> matrix;
for(unsigned int i = 0; i < N; i++){
for(unsigned int j = 0; j < N; j++){
matrix.m[i * N + j] = 0;
for(unsigned int z = 0; z < N; z++){
matrix.m[i * N + j] += a.m[i * N + z] * b.m[z * N + j];
}
}
}
return matrix;
}
我创建了一个子类来管理 3x3 矩阵
class Matrix3 : public MatrixN<3> {
public:
void rotateX(const float radians);
void rotateY(const float radians);
void rotateZ(const float radians);
};
为什么当我执行这个操作时
//Rotations instances of Matrix3
Matrix3 rotation = this->rotation * input.rotation;
我在编译时收到此错误?
no viable conversion from 'MatrixN<3U>' to 'const Matrix3'
【问题讨论】:
-
因为
operator*返回的是MatrixN<N>,而不是Matrix3。 -
input.rotation 是 MatrixN 的类型?