简体   繁体   中英

Syntax Error: missing ; before *

When I try to run these headers:

Direct3D.h

#pragma once

//Library Linker
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib")

//Includes
#include <d3d11.h>

//My Includes
#include "SimpleShaderRessource.h"


class Direct3D
{
public:
    Direct3D();
    ~Direct3D();

    bool Initialize(HWND);
    bool Run();
    void Shutdown();

private:

public:

private:
    ID3D11Device* g_pDevice;
    ID3D11DeviceContext* g_pDeviceContext;
    IDXGISwapChain* g_pSwapChain;
    ID3D11RenderTargetView* g_pRenderTargetView;

    SimpleShaderRessource* g_pSimpleShader;

};

SimpleShaderResource.h

#pragma once

//My Includes
#include "Direct3D.h"

//Library Inludes
#include "CGE_Lib.h"

//Models
#include "Triangle.h"


struct SimpleShaderVertex
{
    CGE::Vector3D position;
    //CGE::Color color;
};

class SimpleShaderResource
{
public:
    SimpleShaderResource();
    ~SimpleShaderResource();

    bool Initialize(ID3D11Device*, ID3D11DeviceContext*, HWND, WCHAR*, WCHAR*);
    bool Render();
    void Shutdown();

private:
    void OutputShaderErrorMessage(ID3DBlob*, HWND, WCHAR*);

public:
    ID3D11InputLayout* g_pLayout;
    Triangle* g_pModel;

};

Triangle.h

#pragma once

#include "Direct3D.h"

class Triangle
{
public:
    Triangle();
    ~Triangle();

    bool Initialize(ID3D11Device*);
    void Shutdown();


    ID3D11Buffer* g_pVertexBuffer;
    ID3D11Buffer* g_pIndexBuffer;

    UINT g_indexCount;
};

I got these errors from VS2015:

C2143   syntax error: missing ';' before '*'    simpleshaderresource.h  34  
C4430   missing type specifier - int assumed. Note: C++ does not support default-int    simpleshaderresource.h  34  
C2238   unexpected token(s) preceding ';'   simpleshaderresource.h  34  
C2143   syntax error: missing ';' before '*'    direct3d.h  34  
C4430   missing type specifier - int assumed. Note: C++ does not support default-int    direct3d.h  34  
C2238   unexpected token(s) preceding ';'   direct3d.h  34  

But I don't see where those syntax errors should come from. #pragma once should prevent circular includes so what did I wrong?

Firstly, as @marcinj pointed, there's a typo. In Direct3D.h , SimpleShaderRessource* g_pSimpleShader; doesn't match the class name SimpleShaderResource .

After fixing that it'll become a circular dependencies issue.

#pragma once should prevent circular includes so what did I wrong?

No. #pragma once is designed to guarantee the current file to be included only once in a single compilation. Preventing circular including is still your responsibility.

And you're including "SimpleShaderRessource.h" in Direct3D.h , and including "Direct3D.h" in SimpleShaderRessource.h .

It seems class Direct3D is not used in SimpleShaderRessource.h , so just remove #include "Direct3D.h" from SimpleShaderRessource.h (and Triangle.h ).

It's a good habit to only include the necessary files.

In SimpleShaderResource.h you include some other headers upfront. If they contain any incompleteness/errors - compiler may encounter problems when analyzing the following code in SimpleShaderResource.h .

As these headers seems not to be external (you include them with "" , not < >), so they are probably yours. Check them carefully, or try to comment them out (program will not compile then, but perhaps it will be easier to find the guilty one; it is usually the last one included)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM