1

There is a C2238 error in the PauseMenu header file on the line: Game* game; It says that ';' is an unexpected token, as well as: C2143 syntax error: missing ';' before '*' on the same line; I have no idea what's wrong in those files, I thought both files are correct.

PauseMenu.h Header File:

#pragma once
#include "EventHandler.h";
#include "MousePressEvent.h";
#include "RectElement.h";
#include "Engine.h";

class PauseMenu :
    public EventHandler
{
public:
    PauseMenu();
    void Show();
    void Hide();
    void onEvent(Event* event);
    void onEvent(MousePressEvent* event);

    Game* game;

private:
    RectElement* background;
    RectElement* resume;
    RectElement* options;
    RectElement* quit;

    bool visible = false;
};

Game.h Header File

#pragma once;
#include "Engine.h";
#include <ctime>;
#include "GameLayer.h";
#include "TextElement.h";
#include "HUDManager.h";
#include <windows.h>;
#include "Collider.h";
#include "CircleCollider.h";
#include "BoxCollider.h";
#include "MouseMoveEvent.h";
#include "CollisionShapeHitEvent.h";
#include "EventHandler.h";
#include "MainMenu.h";
#include "FpsCounter.h";
#include "PauseMenu.h";
#define PI 3.14159265358979323846264338327950288;

class Game :
    public EventHandler
{
public:
    Game(bool dev);
    ~Game();
    void onEvent(Event* event);
    void onEvent(MouseMoveEvent* event);
    void onEvent(KeyPressEvent* event);
    void onEvent(KeyReleaseEvent* event);
    void onEvent(CollisionShapeHitEvent* event);

    MainMenu* mainMenu;
    PauseMenu* pauseMenu;
private:
    Player* player;
    Engine* engine;
};
Sjaak Diemen
  • 61
  • 1
  • 5
  • 1
    Did you forget to `#include "Game.h"` in your `PauseMenu.h`? – Yksisarvinen Oct 21 '18 at 13:16
  • I did, but still the same errors after @Yksisarvinen – Sjaak Diemen Oct 21 '18 at 13:18
  • 2
    You have a cyclic dependency between `Game` and `PauseMenu`, do you need both to contain a pointer to each other? You will need to forward declare one of these classes, or better resolve the cyclic dependency, so the two classes don't need the other. *my previous comment is invalid, you cannot do cyclic-includes* – Yksisarvinen Oct 21 '18 at 13:19
  • https://stackoverflow.com/questions/625799/resolve-build-errors-due-to-circular-dependency-amongst-classes – drescherjm Oct 21 '18 at 13:28
  • Possible duplicate of [Resolve build errors due to circular dependency amongst classes](https://stackoverflow.com/questions/625799/resolve-build-errors-due-to-circular-dependency-amongst-classes) – πάντα ῥεῖ Oct 21 '18 at 13:29

3 Answers3

3

Remove the semicolons after your #includes and #defines. In fact: Remove all semicolons after lines beginning with # if you can't find a reason for them to be there.

And I doubt that you need all those files included in game.h. But you are missing game.h in pausemenu.h or a forward declaration of Game:

class Game;
Swordfish
  • 12,971
  • 3
  • 21
  • 43
  • No semicolon after the pragma either. You need to read up on what the c pre processor does. It interprets every line beginning with a #. Those lines are never seen by the compiler. Cpp doesn’t use semicolons . – vy32 Oct 21 '18 at 13:27
  • 1
    Remove the semicolons at the end of each line which start with # (this means lines starting with #pragma, #define, #include). Macros sometimes include ';' but you have to know what is expected to do with the macro. If you wanna experiment with macros, use the "cpp" (c pre processor) command to see how the code is expanded finally. By the way, normally the header files use the pattern "#ifndef __SYMBOL_H__ #define __SYMBOL_H__ . . . . #endif", not sure about the portability of #pragma once. AFAIK #pragma once is not part of the standard but it is very well supported across compilers. –  Oct 21 '18 at 13:59
1

I guess you have some circular depenency between headers.

To solve it, you can use forward declaration for class Game; in PauseMenu.h Header File before the class PauseMenu.

I guess this way you still maight get other errors but you'll skip the mentioned one

SHR
  • 7,940
  • 9
  • 38
  • 57
0

Try to put destructor ~PauseMenu(){} at the end of class.

Nobody
  • 1
  • 1