我是C++中绝对的初学者,所以我真的很感谢你的帮助!模板参数变量/动态实例化
我目前正在执行一个矩阵类与模板参数的数据类型,尺寸宽度和高度尺寸。
template <class T, int rows, int columns> class Matrix
在乘法函数我要创建的结果矩阵(身高基质A x宽矩阵B),但我收到错误“模板值不能显示在一个常量表达式”。
// overload * for matrix multiplication
template <class T, int rows, int columns>
Matrix<T, rows, columns> operator*(Matrix<T, rows, columns> a, Matrix<T, rows, columns> b) {
Matrix <T, rows, columns> result = new Matrix<T, a->height, b->width>;
// make multiplication here
任何想法如何使一个新的矩阵与给定的类型和从A的高度resp。宽度从B?
太谢谢你了!
首先,您可能需要查看矩阵乘法规则。例如,(r1,c1)矩阵乘以(r2,c2)矩阵需要c1 == r2,并给出(r1,c2)结果。 –