Error C2146: syntax error: missing ';' before the vertex identifier

I usually looked for this error. But in VS C ++ Express, this error occurs almost every error you make. Any ways to get this error below

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

every time i add the following code at the top of the document

 // 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 ), }; 

below is the whole code. I can’t understand what happened. thanks

[EDIT]

 // 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; } 

new mistake

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

Usually this error occurs when what is before the identifier is not known to the compiler. In your case, this means that the compiler has not yet seen SimpleVertex .

+25
source

I definitely see the missing semicolon ; near the end of main right before return true; .

+3
source

An extra comma is added at the end of the last element of the structure. I think it was a mistake.

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

Source: https://habr.com/ru/post/1307895/


All Articles