vendredi 8 juin 2018

C++ file including itself [duplicate]

This question already has an answer here:

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.

Aucun commentaire:

Enregistrer un commentaire