我还没有真正更改我的代码,突然之间无法再编译这个错误:
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
缺少标识符和语法; befor *出现在蛇文件里面,这是:
#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);
};
带有无重载函数的rror,这里有2个参数:
在init中:
Snake *s = new Snake(this, m_config.get());
Visual Studio不会显示任何语法错误或其他任何不编译的内容。清洁没有帮助。
任何人都有一个线索是什么,我做错了所以我可以让它恢复运行?
答案 0 :(得分:2)
根据您对OP的评论,您似乎有一个循环引用问题。
您的Snake
标题中未使用 GameBase
类。
您需要在 GameBase.cpp 文件中声明#include "Snake.h"
声明。