【发布时间】:2021-12-28 06:03:51
【问题描述】:
所以,我将 typedef 声明为:
typedef float Matrix4[4][4];
当我尝试将其初始化为:
void getXRotationMatrix(float theta, Matrix4 ans) {
ans = { {0,0,0,0},{1,1,1,1},{0,0,0,0},{1,1,1,1} };
}
它给出了一个错误:
初始化器值过多
但是,当我将其初始化为:
void getXRotationMatrix(float theta, Matrix4 ans) {
float a[4][4] = { {0,0,0,0},{1,1,1,1},{0,0,0,0},{1,1,1,1} };
ans = a;
}
它没有给出任何错误。谁能解释一下?
【问题讨论】:
-
ans = ...是 assignment 而不是初始化。而且您不能使用大括号括起来的列表分配给数组。