I get
error C2027: use of undefined type ‘Bridge’
and
error C2227: left of ‘->receive’ must point to class/struct/union/generic type
on line *connection1->receive(newMessage,2);
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#define MAXHOST 10
#define MAXPORT 5
#define MAXLAN 8
#define MAXBRIDGE 5
#define MAXLANBRIDGECON 2
using namespace std;
class Bridge;
class Host;
class Message;
class Simulation;
class Lan;
class Message{
//////////////
};
class Host{
Lan * lan1;
int id;
int nextMessageTime;
public:
/////////
};
class Lan{
Bridge *connection1, *connection2;
int bridgeConnection;
Host hostList[MAXHOST];
int id;
int hostCount;
public:
void connect(Bridge * const newBridge)
{
if(bridgeConnection==0)
{
connection1 = newBridge;
}
if(bridgeConnection==1)
{
connection2 = newBridge;
}
bridgeConnection++;
}
void receive(Message newMessage){
*connection1->receive(newMessage,2);
}
};
class Bridge{
/////////////////////
};
void main(){
Simulation newSim;
newSim.create();
return;
}
All the posts before are right, forward declaring is used to prevent circular includes in header files. The Bridge class is forward declared, so that you can specify pointers of that type within your class definition of LAN. Since pointers all have the same size this is ok.
When it comes to using this class the compiler has to know more about the Bridge class, at least its size. But there is no information other than that there is a class named Bridge.
The solution would be either to include the header where Bridge is defined (delete the class Bridge definition if you do this), or to move the implementation of LAN::connect() and LAN::receive() in its own implementation file LAN.cpp and include the Bridge header there which is probably the clean solution.