error C2146: syntax error : missing ';' before identifier 'vertices' [closed]
Asked Answered
C

3

9

I would usually search for this error. But in VS C++ Express, this error comes up for just about every mistake you do. Any how I recieve this error below

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

everytime I add the following code at the top of my 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 code in it's entirety. Cant figure out whats wrong. 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 error

1>c:\users\numerical25\desktop\intro todirectx\msdntutorials\tutorial0\tutorial\tutorial\main.cpp(14) : error C2146: syntax error : missing ';' before identifier 'Pos'
Celisse answered 24/4, 2010 at 21:41 Comment(6)
Is the SimpleVertex class defined in D3Dapp.h?Unkennel
No it isn't, The first appearance of SimpleVertex is where you see it now.Celisse
I edited the code. See the topCelisse
Don't adapt the T[] t syntax given by stakx - it is wrong and should be T t[].Inchmeal
ok, I changed it back. Updated the codeCelisse
You forgot ; at the end of array declaration and also you have unneded , after last array element.Zaneta
H
32
error C2146: syntax error : missing ';' before identifier 'vertices'

Usually this error occurs when what's before the identifier isn't known to the compiler. In your case that means the compiler hasn't seen SimpleVertex yet.

Hamitosemitic answered 24/4, 2010 at 21:49 Comment(3)
I edited the code. See the original postCelisse
@numerical25: The same answer applies. It now complains about a ; missing before Pos. So I would presume it doesn't know D3DXVECTOR3. Was that so hard?Hamitosemitic
I believe it. But at the same time I would suspect an error stating that undeclared or undefined varible has been made. Something along those lines.Celisse
T
3

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

Twocolor answered 24/4, 2010 at 22:8 Comment(1)
Yea, I got that error after I corrected the first one. thanksCelisse
G
1

Extra comma is added at the end of last member of the structure. I think this was the mistake.

SimpleVertex vertices[] =
{
    D3DXVECTOR3( 0.0f, 0.5f, 0.5f ),
    D3DXVECTOR3( 0.5f, -0.5f, 0.5f ),
    D3DXVECTOR3( -0.5f, -0.5f, 0.5f )**,**
}
Gingersnap answered 15/11, 2012 at 9:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.