簡體   English   中英

C-下標值既不是數組,也不是指針,也不是向量

[英]C - subscripted value is neither array nor pointer nor vector

我聲明了一個數組並將2D數組作為參數傳遞。 但是我仍然遇到相同的錯誤:下標值既不是數組,也不是指針,也不是矢量。 對於這條線: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

像這樣的聲明

GLfloat vertex[][3]

僅作為函數參數有效(然后等於GLfloat (*vertex)[3] )。 如果將數組聲明為局部變量或全局變量,則必須為其指定大小。

它在定義mijnplayermijnplayer因為編譯器可以從用於初始化的數據中推斷出大小(大小是隱式設置的)。 如果不這樣做,則編譯器將無法知道數組的大小,因此需要明確指定它。

這是因為shape是數據類型int的變量, 它既不是數組,也不是指針,也不是向量。

要么數據類型錯誤,要么使用的變量錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM