Reputation: 380
I am getting both errors on the same line. Bridge *first in the Lan class. What am i missing?
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
class Lan{
Bridge *first;
Bridge *second;
Host hostList[10];
int id;
};
class Bridge{
Lan lanList[5];
};
class Host{
Lan * lan;
int id;
public:
Host(int newId)
{
id=newId;
}
};
void main(){
return;
}
Upvotes: 1
Views: 2483
Reputation: 19237
Bridge doesn't exist until after the Lan declaration. you should forward-declare Bridge. besides that, Lan won't compile because Host is not known either, and forward declaration won't help, because the compiler needs to know Host's size.
Upvotes: 1
Reputation: 23293
Bridge
is not defined at the moment it is used.
you need a forward declaration so that the compiler knows that Bridge
is a valid class name. before the Lan
class, write:
class Bridge;
Upvotes: 1
Reputation: 26975
Declare Bridge
before Lan
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
class Bridge;
class Lan{
Bridge *first;
Bridge *second;
Host hostList[10];
int id;
};
class Bridge{
Lan lanList[5];
};
Upvotes: 4
Reputation: 73433
You are missing the forward declaration for Bridge
. Otherwise when compiling Lan
class compiler doesn't know what Bridge*
is. You should tell the compiler that Bridge
is a class which you are going to define later. Forward declare it as class Bridge;
before class Lan
Upvotes: 2