我出于教育目的创建了自己的矩阵库。 我创建了一个接受
形式的 4x4 矩阵的构造函数Matrix(float initMatrix[4][4]){
//init operation here
}
上面的构造函数在通过创建一个二维数组然后使用该变量初始化这个对象来创建对象时工作正常,例如:
float my_matrix[4][4] = {{...},{...},{...},{...}}; //shortened for brevity
Matrix matrix(my_matrix);
但是,在执行以下操作时构建失败:
Matrix matrix({{...},{...},{...},{...}});
编译器告诉我
> cannot convert initializer list argument to 'float (*)[4]'
所以我添加了另一个构造函数,如下所示:
Matrix matrix(float matrix(*)[4]){}
我最终得到以下编译器错误。
error: C++ requires a type specifier for all declarations
Vytrix(float input(*)[4]){
有人可以告诉我一种设计构造函数的灵活方法,以便我可以以干净的方式初始化类吗?
最佳答案
语法为:
Matrix(const float (&m)[4][4]);
关于c++ - 如何创建接受二维数组的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51643443/