【发布时间】:2016-04-10 10:24:52
【问题描述】:
我声明了一个数组并传递了一个二维数组作为参数。但是我不断收到同样的错误:下标值既不是数组也不是指针也不是向量。 对于这一行: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: 错误:“形状”的类型冲突
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: 错误:下标值既不是数组也不是指针也不是 向量
顶点[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。
-
您能否编辑您的问题以包含编译器的完整输出,完整且未经编辑,并包括任何可能的信息说明和警告。
-
@JoachimPileborg,已添加。
-
阅读错误信息时,始终从顶部开始。在您的情况下,您有
mijnTest.c:23:59: error: conflicting types for ‘shape’。这应该会引导您仔细查看函数声明及其参数。 -
开始,函数有两个不同的参数:
drawVertex(),它们都被命名为`shape'