【问题标题】:suddenly an: syntax error: identifier [duplicate]突然一个:语法错误:标识符[重复]
【发布时间】:2014-06-28 04:54:01
【问题描述】:

我并没有真正改变我的代码,突然因为这个错误不能再编译它:

Error   29  22  error C2061: syntax error : identifier 'GameBase'   c:\users\...\documents\visual studio 2013\projects\first game\first game\snake.h    1   First Game
Error   61  22  error C2061: syntax error : identifier 'GameBase'   c:\users\...\documents\visual studio 2013\projects\first game\first game\snake.h    1   First Game
Error   30  33  error C2143: syntax error : missing ';' before '*'  c:\users\...\documents\visual studio 2013\projects\first game\first game\snake.h    1   First Game
Error   31  33  error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\users\benjamin\documents\visual studio 2013\projects\first game\first game\snake.h   1   First Game
Error   62  33  error C2143: syntax error : missing ';' before '*'  c:\users\...\documents\visual studio 2013\projects\first game\first game\snake.h    1   First Game
Error   63  33  error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\users\...\documents\visual studio 2013\projects\first game\first game\snake.h    1   First Game
Error   69  136 error C2661: 'Snake::Snake' : no overloaded function takes 2 arguments  c:\users\...\documents\visual studio 2013\projects\first game\first game\gamebase.cpp   1   First Game

标识符和语法缺失;之前 * 出现在蛇文件中,即:

#pragma once

#include "GameBase.h"
#include <list>

using namespace std;
enum State
{
    POSX, NEGX, POSY, NEGY, POSZ, NEGZ
};

enum ChangeState
{
    RIGHT, LEFT, UP, DOWN
};

class Snake : public Actor
{
public:
    Snake(GameBase *game, Config *config); // HERE theidentifier
    ~Snake();

    //interface methods
    void update(float delta);
    void render(ID3D11DeviceContext *context, ID3D11Buffer *worldBuffer);

    void setState(ChangeState& state);
private:
    /*Containing the pointer to the cubes of the snake*/
    list<Cube *> m_cubes;
    GameBase *m_game; // here the syntax ; before *
    //timer for updating
    float m_updateTime;
    float m_timer;
    int m_cubeSize = 21;

    State m_state;
};

最后但并非最不重要的是这里的游戏基地:

#pragma once

#include "Dx11Base.h"
#include "Cube.h"
#include "Wall.h"
#include "Group.h"
#include "Camera.h"
#include "Logger.h"
#include "InputHandler.h"
#include "Snake.h"

#include <vector>
class GameBase : public Dx11Base
{
public:
    GameBase();
    virtual ~GameBase();
    /*load all shader and so on*/
    bool load();
    /*unload to be save when changing*/
    void unload();
    /*update the gamestate */
    void update(float delta);
    /*presents the new game state*/
    void render();
    /*Callback for the window its size changes*/
    void callBack();
    //set vscync or not
    void setVsync(bool b);

    void addToGroup(Actor* a);

    int m_world[21][21][21];

private:
    ID3D11VertexShader* m_vertexShader;
    ID3D11PixelShader* m_pixelShader;

    ID3D11InputLayout* m_inputLayout;

    ID3D11BlendState* m_alphaBlendState; // generel blend state

    ID3D11Buffer* m_viewCB; //constant buffer for view matrix
    ID3D11Buffer* m_projCB; //constant buffer for view matrix
    ID3D11Buffer* m_worldCB; //constant buffer for view matrix
    ID3D11Buffer* m_cameraPosCB; //constant buffer for view matrix

    XMMATRIX m_projectionMatrix; // viewport matrix

    Camera m_camera;
    InputHandler m_input;

    /*the maingroup containing the actors*/
    Group m_group;

    /*compiles and creates the shader and also the INPUTLAYOUT!*/
    bool compileAndCreateShader(char* vertexShader, char* pixelShader);
};

没有重载函数的错误在这里需要2个参数:

在初始化中:

Snake *s = new Snake(this, m_config.get());

Visual Studio 不会显示任何语法错误或其他任何它无法编译的内容。清洁没有帮助。

任何人都知道发生了什么以及我做错了什么,所以我可以让它重新运行吗?

【问题讨论】:

  • “我现在不能。”废话。您可以使用免费提供的工具,在没有任何专用服务器的情况下使用版本控制。
  • 尝试在Snake.h 中声明GameBase,直到您对包含订单进行排序。
  • 您在 GameBase.hSnake.h 之间有循环包含依赖项
  • Snake 类未在您的GameBase 标头上使用。为什么你不在你的 cpp 文件中声明包含?
  • 使用命名空间标准;请不要在标题中这样做!

标签: c++


【解决方案1】:

根据您的 OP 上的 cmets,您似乎遇到了循环引用问题。

Snake 类未用于您的 GameBase 标头。

您需要在 GameBase.cpp 文件中声明 #include "Snake.h" 声明。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多