Kacper Fałat
Kacper Fałat

Reputation: 643

Redefinition C++ Issue, Multiple Header

I now working on project with alot of classes and sometimes i need to include like :

CSConnection.h in Player.h and Player.h in CSConnection.h, and now there my compiler got conflicts like Class name was not defined.

Headers had guard, where is problem ?

Upvotes: -6

Views: 82

Answers (3)

Ed Heal
Ed Heal

Reputation: 60027

Forward declaration - see http://en.wikipedia.org/wiki/Forward_declaration or Perhaps the use of a guard 'i.e. #ifdef ...' - http://en.wikipedia.org/wiki/Include_guard

Upvotes: 0

mel-
mel-

Reputation: 533

Include guards prevent a file from being included multiple times within the same file, but can not help you with cyclic includes. What you probably want is forward declaration, but that depends on what's in your include files.

Upvotes: -1

totowtwo
totowtwo

Reputation: 2147

Circular dependencies are just bad design. If you feel the urge to have a child/owned object "know about" its parent/owner, you should pass the child a std::function instead of a full reference to the owner.

Upvotes: 1

Related Questions