new cpp file = circular dependency

The Partridge Family were neither partridges nor a family. Discuss.
egizz983
Posts: 311
Joined: August 27th, 2016, 12:30 pm

new cpp file = circular dependency

Post by egizz983 » December 13th, 2016, 3:45 pm

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
Attachments
Game.rar
(1.13 MiB) Downloaded 143 times

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: new cpp file = circular dependency

Post by albinopapa » December 13th, 2016, 5:06 pm

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.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

egizz983
Posts: 311
Joined: August 27th, 2016, 12:30 pm

Re: new cpp file = circular dependency

Post by egizz983 » December 13th, 2016, 5:20 pm

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

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: new cpp file = circular dependency

Post by albinopapa » December 14th, 2016, 2:28 am

No, figured you would have kept it in there for testing. Let me try it and see.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: new cpp file = circular dependency

Post by albinopapa » December 14th, 2016, 2:55 am

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.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: new cpp file = circular dependency

Post by albinopapa » December 14th, 2016, 2:56 am

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()
{}
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: new cpp file = circular dependency

Post by albinopapa » December 14th, 2016, 2:58 am

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.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: new cpp file = circular dependency

Post by albinopapa » December 14th, 2016, 3:11 am

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.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: new cpp file = circular dependency

Post by albinopapa » December 14th, 2016, 3:16 am

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));
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

egizz983
Posts: 311
Joined: August 27th, 2016, 12:30 pm

Re: new cpp file = circular dependency

Post by egizz983 » December 14th, 2016, 9:06 am

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 ?

Post Reply