Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Circular dependencies missing type specifier – int assumed. Note: C++ does not support default-int

I am still new with c++ and I was told that #pragma once was supposed to take care of circular dependencies

My GameManager.h and GameSetting.h both need to know each other and each have a pointer of the other

for my GameSettings.h i have:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#pragma once
#include "PlayerManager.h"
#include <fstream>
#include "GameManager.h";

class GameSettings {
private:
PlayerManager* pM;
GameManager* gM;
vector<Player*> players;

bool inGame = false;
double betValue = 5;
bool allowSplit = true;
bool allowInsurance = true;
GameSettings(PlayerManager* pM, GameManager* gM) { this->pM = pM; this->gM = gM; }

struct GameSettingData {
    vector<int> playersId;
    double betValue;
    bool allowSplit;
    bool allowInsurance;
};

… function declarations…

for the GameSettings.cpp I only have the #include "GameSettings.h"

And for the GameManager I only have

#pragma once
#include "GameSettings.h"

class GameManager {
private:
    bool isActive = false;
    GameSettings *gS;
public:
    bool getIsActive() { return isActive; }

bool startGame() { return true; }
};

When I remove any mention of GameSettings in GameManager everything work

I mostly know c# so this kind of circular dependencies is kind of new for me.
I did try to look at other similar questions but it did not help

>Solution :

Use a forward declaration of GameSettings in GameMager.h. Pointers do not need complete class definitions until they are derefenced.

#pragma once

class GameSettings;

class GameManager {
private:
    bool isActive = false;
    GameSettings *gS;
public:
    bool getIsActive() { return isActive; }

bool startGame() { return true; }
};

GameManager and PlayerManager can also participate in forward declarations in GameSettings.h.

#pragma once
#include <fstream>

class PlayerManager;
class GameManager;

class GameSettings {
private:
PlayerManager* pM;
GameManager* gM;
vector<Player*> players;

bool inGame = false;
double betValue = 5;
bool allowSplit = true;
bool allowInsurance = true;
GameSettings(PlayerManager* pM, GameManager* gM) { this->pM = pM; this->gM = gM; }

struct GameSettingData {
    vector<int> playersId;
    double betValue;
    bool allowSplit;
    bool allowInsurance;
};

Set required #include in .cpp files.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading