我声明了一个数组并将二维数组作为参数传递。但是我不断收到同样的错误:下标值既不是数组也不是指针也不是 vector 。 对于这条线:vertex[i][j-1] = shape[i][j];
我该如何解决?
头文件:
GLfloat mijnplayer [][4] ={
{0,-0.091057,0.198079,0.084590},
{0,-0.158043,0.158043,0.071039},
{0,-0.071039,0.158043,0.158043}};
函数调用:
int main(void)
{
drawVertex(mijnplayer,3,1);
}
void drawVertex(GLfloat shape[][4], int numberVertex, int shape)
{
int i,j;
GLfloat vertex[][3]={0};
//convert 4element array to 3 element array
for(i=0;i<numberVertex;i++)
{
for(j=1;j<4;j++)
{
vertex[i][j-1] = shape[i][j];
}
}
for(i=0;i<numberVertex;i++)
{
glVertex3fv(vertex[i]);
}
}
编辑:
完整的编译器输出:
cc -c -o mijnTest.o mijnTest.c
mijnTest.c:23:59: 错误:“shape”类型冲突
void drawVertex(GLfloat shape[][4], int numberVertex, int shape) ^
mijnTest.c:23:25: 注意:“形状”的先前定义在这里
void drawVertex(GLfloat shape[][4], int numberVertex, int shape) ^
mijnTest.c:在函数“drawVertex”中:
mijnTest.c:43:26: 错误:下标值既不是数组也不是指针也不是 vector
顶点[i][j-1] = 形状[i][j]; ^
mijnTest.c:在函数“drawScene”中:
mijnTest.c:69:2: 警告:从中传递“drawVertex”的参数 1 不兼容的指针类型[默认启用]
drawVertex(assen,6,0); ^
mijnTest.c:23:6: 注意:应为“GLfloat ()[4]”,但参数是类型 ‘GLfloat ()[3]’
void drawVertex(GLfloat shape[][4], int numberVertex, int shape) ^
make: *** [mijnTest.o] 错误 1
最佳答案
因为shape
是int
数据类型的变量,既不是数组也不是指针也不是 vector 。
要么你的数据类型错误,要么你只是使用了错误的变量。
关于C - 下标值既不是数组也不是指针也不是 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36528563/