melih
melih

Reputation: 380

error C4430: missing type specifier / error C2143: syntax error : missing ';' before '*'

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

Answers (5)

just somebody
just somebody

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

Adrien Plisson
Adrien Plisson

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

js.
js.

Reputation: 1869

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

Upvotes: 1

Alexey Malistov
Alexey Malistov

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

Naveen
Naveen

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

Related Questions