Including a header which relies on including the first header

I'm entirely dumb-founded as how to address this because I get one of 2 errors:
error: ISO C++ forbids declaration of `Player' with no type|
multiple definition of `...'|

This is how things are layed out (sliced from code):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//Server.h
#pragma once
#include <climits>
#include <vector>
#include "39dll/39dll.h"
#include "Player.h"

class Server
{
public:
   static int MAX_PLAYERS;
   static Player** Players;  //This errors, relies on Player.h
   static vector<CSocket*> Queue  //This errors, relies on 39dll.h;
};


1
2
3
4
5
6
7
8
9
//Player.h
#pragma once
#include "Server.h"

class Player
{
public:
   CSocket* socket;  //This errors, relies on the header 39dll.h in Server.h
};


So basically these headers need each other, the class types are messing each other up by either not being defined, or re-defining.

~
Here is a link to the Codeblocks project, the errors/problem is quite apparent when built.
25.52kb zip
http://www.mediafire.com/?b4w6140nx90ca3w
Last edited on
Hi,
Can we see the full code....
You have only pointers to the other class, so forward declare.
@Firix
End of post I posted a url to all the source code.

@Zhuge
What would I have to do with the layout if I were to forward declare the objects?
Just put class CSocket; in front of the player class instead of including the header, and put class Player; and class CSocket; in front of the Server class and remove the includes.

EDIT:
http://www.cplusplus.com/forum/beginner/6075/#msg27289
The post by jsmith basically explains it.
Last edited on
Thankyou! This is such a useful thing to learn, really didn't know this was possible. It wasn't in my C++ book nor posts which I searched for online.

I will let you know how I get on, really hope I can get this working.
Brilliant, absolutely brilliant. This way the key to the puzzle. Thankyou so much, I am forever in your debt...
Topic archived. No new replies allowed.