Page 1 of 2
new cpp file = circular dependency
Posted: December 13th, 2016, 3:45 pm
by egizz983
Why adding cpp file to GameStateLogin.h cause me circular dependency ?
no includes nothing just make new cpp file for GameStateLogin.h and i got 70 errors
Re: new cpp file = circular dependency
Posted: December 13th, 2016, 5:06 pm
by albinopapa
There were no errors when I built and ran it. Try going to the Menu / Build / Rebuild and see if the problem is still there.
Re: new cpp file = circular dependency
Posted: December 13th, 2016, 5:20 pm
by egizz983
did u made GameStateLogin.cpp ? cuz i upload without it
https://s27.postimg.org/bez9ukoo3/Untitled_1.jpg
and without him its ok everything works
Re: new cpp file = circular dependency
Posted: December 14th, 2016, 2:28 am
by albinopapa
No, figured you would have kept it in there for testing. Let me try it and see.
Re: new cpp file = circular dependency
Posted: December 14th, 2016, 2:55 am
by albinopapa
Ok, so here's the problem: Adding #include "ChiliWin.h" in a header file or any other header that includes the ChiliWin.h file will probably keep causing you issues.
How I resolved the issue was moving the include to the CPP file, and adding #define FULL_WINTARD before any of the includes.
You might be able to get away with adding the #define FULL_WINTARD in the header before the rest of the includes, but I didn't try it.
Re: new cpp file = circular dependency
Posted: December 14th, 2016, 2:56 am
by albinopapa
Example:
GameStateLogin.cpp
Code: Select all
#define FULL_WINTARD
#include "../Game.h"
#include "GameStateLogin.h"
GameStateLogin::GameStateLogin( Game * gm )
:
GameStateFirstPhase( gm )
{}
void GameStateLogin::Draw( Graphics & gfx )
{}
void GameStateLogin::Update()
{}
Re: new cpp file = circular dependency
Posted: December 14th, 2016, 2:58 am
by albinopapa
You could add a header file with just the following lines, and include it instead of having to type the two lines in every CPP file
ChiliWintard.h
Code: Select all
#pragma once
#define FULL_WINTARD
#include "Framework\ChiliWin.h"
Just remember to include this file before any others.
Also, it's going to depend on where the file resides, here I put the ChiliWintard.h file in Engine, instead of the Framework folder.
Re: new cpp file = circular dependency
Posted: December 14th, 2016, 3:11 am
by albinopapa
By the way, do you realize you are leaking memory when you change states?
Code: Select all
void Game::SetGameState(GameState* newstate)
{
pCurrentState = newstate;
}
You should probably either make pCurrentState a unique_ptr, or be deleting your current state before assigning the new state.
Re: new cpp file = circular dependency
Posted: December 14th, 2016, 3:16 am
by albinopapa
Game.h
Code: Select all
#include <memory>
void SetGameState(std::unique_ptr<GameState> &&newstate);
std::unique_ptr<GameState> pCurrentState;
Game.cpp
Code: Select all
void Game::SetGameState( std::unique_ptr<GameState>&& newstate )
{
pCurrentState = std::move( newstate );
}
then for the different game states when changing states:
Code: Select all
pGame->SetGameState(std::make_unique<GameStateSelectServer>(pGame));
Re: new cpp file = circular dependency
Posted: December 14th, 2016, 9:06 am
by egizz983
ChiliWintard.h
i have to include this into each of header and cpp file or only into each of cpp files?
And as far as i know i need to delete only when i call it with a new ? or i am wrong ?