Say I have created two classes: Tires, and Car.
So I have four files: Tires.cpp, Tires.h, Car.cpp, Car.h.
The Car constructor takes Tires as its parameter. But I am not sure how to modify Car.h to include Tires.h.
Here's what I've done so far (note: they are in separate files)
Tires.h
#include <iostream>
using namespace std;
class Tires
{
private:
int numTires;
public:
Tires();
};
Tires.cpp
#include <iostream>
#include "Tires.h"
using namespace std;
Tires::Tires()
{
numTires = 4;
}
Car.h
#include <iostream>
#include "Tires.h"
using namespace std;
class Tires; // Tried taking out forward declaration but still didn't work
class Car
{
private:
Tires tires;
public:
Car(Tires); // Edited. Thanks to Noah for pointing out.
};
Car.cpp
#include <iostream>
#include "Car.h"
#include "Tires.h"
using namespace std;
Car::Car(Tires _tires)
{
tires = _tires;
}
Thanks