tags:

views:

234

answers:

5

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;
}
+2  A: 

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

Naveen
+4  A: 

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];
};
Alexey Malistov
+1. But next problem will be the Host *definition*, required for Lan :)
Johannes Schaub - litb
so it's all about declarations. Thanks
melih
+1  A: 

Just put a class Bridge; before the declaration of the Lan class.

js
+1  A: 

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;
Adrien Plisson
+1  A: 

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.

just somebody