Error : not declared in this scope

1
2
3
4
5
6
7
8
9
#ifndef ROAD_H_
#define ROAD_H_

#include <vector>
#include <string>
#include "Car.h"
using namespace std;

class Road{


1
2
3
4
5
6
7
8
9
10
11
12
13
#ifndef CAR_H
#define CAR_H_

#include <string>
#include <map>
#include "Road.h"
using namespace std;

class Car
{

public:
  Car(string& ID, string& roadPlan,int time, const map<string,Road>& Roads);


I have 2 classes and in "Road" i have field type "Car" and in "Car" i have "Road". When I compile "Road" i get error in 'Car.h' file : ‘Road’ was not declared in this scope.

Anyone has a solution?
Thank you!
In first file remove #include "Car.h" and write class Car; before class Road.
in second file remove #include "Road.h" and write class Road; before class Car.
You may find some more hints when looking for "forward declaration" in this forum.
Topic archived. No new replies allowed.