语法错误:缺失;之前*

时间:2016-06-01 10:24:24

标签: c++ include-guards

当我尝试运行这些标题时:

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

我从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  

但我不知道这些语法错误应该来自哪里。 #pragma once应该阻止循环包含所以我错了什么?

2 个答案:

答案 0 :(得分:2)

首先,正如@marcinj指出的那样,这是一个错字。在Direct3D.h中,SimpleShaderRessource* g_pSimpleShader;与类名SimpleShaderResource不匹配。

在确定它将成为循环依赖问题之后。

  

#pragma once应该阻止循环包含所以我错了什么?

没有。 #pragma once旨在保证当前文件仅在单个编译中包含一次。防止循环包括仍然是你的责任。

您在"SimpleShaderRessource.h"中加入Direct3D.h,并在"Direct3D.h"中加入SimpleShaderRessource.h

似乎Direct3D中没有使用SimpleShaderRessource.h类,因此只需从#include "Direct3D.h"(和SimpleShaderRessource.h)中删除Triangle.h

只包含必要的文件是一个好习惯。

答案 1 :(得分:0)

SimpleShaderResource.h中,您预先包含了一些其他标题。如果它们包含任何不完整性/错误 - 编译器在分析SimpleShaderResource.h中的以下代码时可能会遇到问题。

由于这些标题似乎不是外部的(您将它们包含在&#34;&#34;而不是&lt;&gt;)中,因此它们可能属于您的标题。仔细检查它们,或者尝试将它们注释掉(程序将不会编译,但也许会更容易找到有罪的;它通常是包含的最后一个)

相关问题