2013-05-20 50 views
1

我有一个Game类 -语法错误:标识符未找到...但我已包含它? C++

Game.h

#pragma once 

#include "D3DGraphics.h" 
#include "Mouse.h" 
#include "Screen.h" 
#include "Script.h" 

class Game 
{ 
public: 
    Game(HWND hWnd, const MouseServer &mouseServer, const ScreenServer &screenServer); 
    void Go(); 
    void Config(); 

private:  
    void ComposeFrame(); 

    D3DGraphics gfx; 
    MouseClient mouse; 
    ScreenClient screen; 

    Script * scripts[ 1 ]; 
}; 

我有一个D3DGraphics类 -

D3DGraphics.h

#pragma once 

#include <d3d9.h> 
#include <d3dx9.h> 

#include "Screen.h" 
#include "Script.h" 

#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE) 

struct CUSTOMVERTEX 
{ 
    FLOAT x, y, z, rhw; // from the D3DFVF_XYZRHW flag 
    DWORD color; // from the D3DFVF_DIFFUSE flag 
}; 

class D3DGraphics 
{ 
public: 
    D3DGraphics(HWND hWnd, ScreenClient screenClient); 
    ~D3DGraphics(); 

    void Begin(); 
    void End(); 
    void Present(); 

    void CreateViewport(); 
    void DefineText(Script *script); 

    LPDIRECT3D9 d3dObject; 
    LPDIRECT3DDEVICE9 d3dDevice; 
    D3DPRESENT_PARAMETERS presParams; 
    HRESULT hr; 

    float ResizeLockRatio(float width, float height, float scalingWidth); 
    float GetGameOffset(float resizedImageHeight); 

    void DrawRectangle(int x, int y, int width, int height, D3DCOLOR backgroundColor); 
    void DrawActionBar(); 
    void RenderText(Script *script); 
private: 
    LPDIRECT3DVERTEXBUFFER9 vBuffer; 
    ScreenClient screen; 
}; 

公告游戏类有

D3DGraphics gfx; 
Script * scripts[ 1 ]; 

在我Game.cpp我做一个版本D3DGraphics的,并放置在GFX:

Game.cpp

#include "Game.h" 

Game::Game(HWND hWnd, const MouseServer &mouseServer, const ScreenServer &screenServer) 
    : mouse(mouseServer), 
     screen(screenServer), 
     gfx(hWnd, screen) 
{ 
    //gfx.d3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); 

    std::string debugStringResult; 
    std::stringstream debugString; 
    debugString << "Mouse X: " << mouse.GetMouseX() << ",\nMouse Y: " << mouse.GetMouseY() << ",\nLeft mouse down: " << mouse.LeftMouseDown() << ",\nRight mouse down: " << mouse.RightMouseDown() << ",\nScreen width: " << screen.GetScreenWidth() << ",\nScreen height: " << screen.GetScreenHeight() << "\nSystem resolution: " << screen.GetWindowWidth() << " x " << screen.GetWindowHeight(); 
    debugStringResult = debugString.str(); 
     scripts[ 0 ] = new Script(gfx, "Arial", 0, 0, 255, 0, debugStringResult, 10, 10, (screen.GetWindowWidth() - 10), (screen.GetWindowHeight() - 10)); 
} 

我有一个脚本类 -

Script.h

#pragma once 

#include "D3DGraphics.h" 
#include <sstream> 

class Script 
{ 
public: 
    Script(D3DGraphics gfx, 
      LPCSTR font, 
      int alpha, int r, int g, int b, 
      std::string text, 
      float x, float y, float width, float height); 

    LPCSTR font; 
    int alpha, r, g, b; 
    std::string text; 
    float x, y, width, height; 
    D3DCOLOR color; 
    RECT rect; 
    ID3DXFont *handle; 
private: 
}; 

我的剧本的构造是这样的:

Script.cpp

#include "Script.h" 

Script::Script(D3DGraphics gfx, 
       LPCSTR font, 
       int alpha, int r, int g, int b, 
       std::string text, 
       float x, float y, float width, float height) 
{ 
    gfx.DefineText(this); 
} 

等。现在的错误,当我编译我的应用程序出现为:

Error 1 error C2061: syntax error : identifier 'D3DGraphics' c:\users\james\documents\visual studio 2012\projects\thegame\thegame\script.h 9 1 TheGame 
Error 8 error C2061: syntax error : identifier 'D3DGraphics' c:\users\james\documents\visual studio 2012\projects\thegame\thegame\script.h 9 1 TheGame 
Error 9 error C2661: 'Script::Script' : no overloaded function takes 11 arguments c:\users\james\documents\visual studio 2012\projects\thegame\thegame\game.cpp 14 1 TheGame 
Error 10 error C2061: syntax error : identifier 'Script' c:\users\james\documents\visual studio 2012\projects\thegame\thegame\d3dgraphics.h 28 1 TheGame 
Error 11 error C2061: syntax error : identifier 'Script' c:\users\james\documents\visual studio 2012\projects\thegame\thegame\d3dgraphics.h 40 1 TheGame 
Error 12 error C2660: 'D3DGraphics::DefineText' : function does not take 1 arguments c:\users\james\documents\visual studio 2012\projects\thegame\thegame\script.cpp 9 1 TheGame 
Error 13 error C2061: syntax error : identifier 'D3DGraphics' c:\users\james\documents\visual studio 2012\projects\thegame\thegame\script.h 9 1 TheGame 
Error 16 error C2061: syntax error : identifier 'D3DGraphics' c:\users\james\documents\visual studio 2012\projects\thegame\thegame\script.h 9 1 TheGame 

线Script.h的9:

Script(D3DGraphics gfx,... 

老实说,我不知道这到底是怎么回事?有没有人有线索,在过去的2个小时里,我一直在嘲笑代码,像一只死的动物。

+2

你知道D3D正在编译之前的脚本? –

回答

0

你有一个循环依赖,所以你可能需要指定你想脚本编译之前D3DGraphics,这是通过:

#pragma once 

#include "D3DGraphics.h" 
#include <sstream> 

class D3DGraphics; 

class Script 
{ 
public: 
    Script(D3DGraphics gfx, 
      LPCSTR font, 
      int alpha, int r, int g, int b, 
      std::string text, 
      float x, float y, float width, float height); 

    LPCSTR font; 
    int alpha, r, g, b; 
    std::string text; 
    float x, y, width, height; 
    D3DCOLOR color; 
    RECT rect; 
    ID3DXFont *handle; 
private: 
}; 
+0

我有在这里自我窥探吗?当我宣布如上,然后我得到了同样的错误了D3DGraphics:错误错误C2061:语法错误:标识符 '脚本' \t C:\用户\詹姆斯\文件\的Visual Studio 2012 \项目\ thegame \ thegame \ d3dgraphics .H \t TheGame – Jimmyt1988

2

正如Need4Sleep提到的,您的D3DGraphics.hScript.h夹杂的问题。解决这个问题的一种方法是只声明你的脚本类,而不是在D3DGraphics.h中包含它的头部。

例如:

#pragma once 

#include <d3d9.h> 
#include <d3dx9.h> 

#include "Screen.h" 

#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE) 

class Script; 
struct CUSTOMVERTEX 
{ 
    FLOAT x, y, z, rhw; // from the D3DFVF_XYZRHW flag 
    DWORD color;   // from the D3DFVF_DIFFUSE flag 
}; 

class D3DGraphics 
{ 
public: 
    D3DGraphics(HWND hWnd, ScreenClient screenClient); 
    ~D3DGraphics(); 

    // rest of D3DGraphics's definition 
}; 

这只要D3DGraphics不具有内联使用您Script类实质性的方式方法的工作。例如。指向脚本的指针很好。

相关问题