1

I have two classes that are inter-dependent. I am pretty sure, I am designing it in a wrong way but I don't know how to fix it.

So, I have a situation like following- My car class includes the truck class.

#include "stdafx.h"
#include "truck.h"

using namespace std;

class car {
    int wheels;
    float speed;

public:
    car(int wheels, int speed);
    int numberOfWheels();
    float speedRate();

    bool isFaster(truck & truck);
};

and then my truck class needs to include the car class-

#include "stdafx.h"
#include "car.h"

using namespace std;

class truck {
    int wheels;
    float speed;

public:
    truck(int wheels, int speed);
    int numberOfWheels();
    float speedRate();

    bool isFaster(car & car);
};

I am getting the include itself error and I know why but I can't find a way to get around that.

Can anyone please help me with it.

Natasha
  • 6,651
  • 3
  • 36
  • 58

1 Answers1

1

Use forward declaration

In any one header file you can declare other class as forward declarations

Dinesh Chowdary
  • 252
  • 2
  • 3