0

i haven't really changed anything of my code and suddenly cant compile it anymore with this error:

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

The identifier and the syntax missing ; befor * occure inside of the snake file which is this:

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

And last but not least the gamebase here:

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

with the rror of the no overloaded function takes 2 arguments here:

in the init:

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

Visual studio does not show any syntax errors or anything else it just dont compile. Cleaning didn't help.

Anyone has a clue whats going on and what i am doing wrong so i can get it back to running again?

BennX
  • 6,096
  • 3
  • 34
  • 81
  • "haven't really changed anything" - clearly you changed *something*, so you just need to identify what that something was (you're using version control, right?). – Oliver Charlesworth May 10 '14 at 13:39
  • Tried a clean rebuild already? VS somtimes hickups with precompiled headers. – πάντα ῥεῖ May 10 '14 at 13:39
  • @OliCharlesworth i need to say that i didnt use a version control atm. I simply cant at the moment. I have changed nothing i just added a method which didnt get called or anything yet. Outlining does not change something. Yes as mentioned i did a clean and rebuild already. – BennX May 10 '14 at 13:40
  • Usually error message include a line number you can look at. – brian beuning May 10 '14 at 13:42
  • "i haven't really changed anything of my code" - this is always a lie. – Richard Hodges May 10 '14 at 13:42
  • i create an instance of the snake to add it to the group of my rendering. Yes it has a line number which i already marked int he code above. I could upload the whole project so you can have a look at it and see whats wrong .. – BennX May 10 '14 at 13:43
  • 1
    "I simply cant at the moment." Nonsense. You can use version control without any dedicated server, using freely available tools. –  May 10 '14 at 13:43
  • @hvd i know but i didnt do it yet. and yes i know this breaks my neck right now – BennX May 10 '14 at 13:44
  • 1
    Try forward declaring `GameBase` in `Snake.h` until you sort your include order out. – gha.st May 10 '14 at 13:45
  • 3
    You have circular include dependencies between `GameBase.h` and `Snake.h` – fredoverflow May 10 '14 at 13:46
  • Forwarding correced it. So its a circular. How to i get rid of it? I need that kinde of dependencie – BennX May 10 '14 at 13:48
  • Why, exactly, do you think you need that kind of dependency? – David Hammen May 10 '14 at 13:49
  • 1
    `Snake` class is not used on your `GameBase` **header**. Why you doesn't declare include on your cpp file instead? – HuorSwords May 10 '14 at 13:50
  • @HuorSwords your right if i include it inside of the .cpp it does work without forwarding. Thanks for all the help i guess i know what todo. Hell alot of organizating the code.... – BennX May 10 '14 at 13:53
  • 3
    using namespace std; please don't do that in headers! – poljpocket May 10 '14 at 13:56

1 Answers1

3

By the comments on your OP, it seems that you have a circular reference problem.

Snake class is not used on your GameBase header.

You need to declare #include "Snake.h" statement on your GameBase.cpp file instead.

HuorSwords
  • 2,085
  • 1
  • 17
  • 32