错误C2146:语法错误:缺少';'之前标识符'顶点'

错误C2146:语法错误:缺少';'之前标识符'顶点'

问题描述:

我通常会搜索此错误。但是在VS C++ Express中,这个错误会出现在你做的每一个错误上。任何我如何收到以下错误C2146:语法错误:缺少';'之前标识符'顶点'

error C2146: syntax error : missing ';' before identifier 'vertices' 

每次这个错误我添加以下代码在我的文档

// Create vertex buffer 
SimpleVertex vertices[] = 
{ 
    D3DXVECTOR3(0.0f, 0.5f, 0.5f), 
    D3DXVECTOR3(0.5f, -0.5f, 0.5f), 
    D3DXVECTOR3(-0.5f, -0.5f, 0.5f), 
}; 

的顶部下方是它的全部代码。不能弄清楚什么是错的。感谢

[编辑]

// include the basic windows header file 
#include "D3Dapp.h" 


class MyGame: public D3Dapp 
{ 
    public: 
     bool Init3d(); 
}; 
MyGame game; 

struct SimpleVertex 
{ 
    D3DXVECTOR3 Pos; // Position 
}; 


// the entry point for any Windows program 
int WINAPI WinMain(HINSTANCE hInstance, 
        HINSTANCE hPrevInstance, 
        LPSTR lpCmdLine, 
        int nCmdShow) 
{ 
    game.InitWindow(hInstance , nCmdShow); 
    return game.Run(); 
} 


bool MyGame::Init3d() 
{ 
    D3Dapp::Init3d(); 
    // Create vertex buffer 
    SimpleVertex vertices[] = 
    { 
     D3DXVECTOR3(0.0f, 0.5f, 0.5f), 
     D3DXVECTOR3(0.5f, -0.5f, 0.5f), 
     D3DXVECTOR3(-0.5f, -0.5f, 0.5f), 
    } 

    return true; 
} 

新的错误

1>c:\users\numerical25\desktop\intro todirectx\msdntutorials\tutorial0\tutorial\tutorial\main.cpp(14) : error C2146: syntax error : missing ';' before identifier 'Pos' 
+1

'D3Dapp.h'中定义了'SimpleVertex'类吗? – 2010-04-24 21:46:21

+0

不,不是,SimpleVertex的第一个外观就是你现在看到的地方。 – numerical25 2010-04-24 21:51:43

+0

我编辑了代码。见顶部 – numerical25 2010-04-24 21:55:49

error C2146: syntax error : missing ';' before identifier 'vertices' 

之前标识符不知道的编译器时,什么是通常会出现此错误。在你的情况下,这意味着编译器还没有看到SimpleVertex

+0

我编辑了代码。查看原文 – numerical25 2010-04-24 21:56:25

+1

@ numerical25:同样的答案适用。它现在抱怨在'Pos'之前缺少';'。所以我会假定它不知道'D3DXVECTOR3'。那很难吗? – sbi 2010-04-24 22:01:44

+0

我相信。但是同时我会怀疑有一个错误,指出未声明或未定义的变量已经被创建。沿着这些线的东西。 – numerical25 2010-04-24 22:05:49

return true;前右我确实看到缺少分号;main末。

+0

是的,我纠正了第一个错误后得到了这个错误。谢谢 – numerical25 2010-04-24 22:11:01

额外的逗号是在结构的最后一个成员的末尾添加的。我认为这是错误的。

SimpleVertex vertices[] = 
{ 
    D3DXVECTOR3(0.0f, 0.5f, 0.5f), 
    D3DXVECTOR3(0.5f, -0.5f, 0.5f), 
    D3DXVECTOR3(-0.5f, -0.5f, 0.5f)**,** 
}