I have made a little snippet of what my project is essentially based on - except much bigger. I am having a hard to grasping this particular concept. I need to make a car class which inherits the vehicle class and then there must be separate classes such as window, door, engine etc... I need to access those classes through the car class to adjust its "properties"
#include <iostream>
using namespace std;
class Vehicle
{
virtual void print() = 0;
};
class Car : public Vehicle
{
virtual void print();
Wheel tires[4];
};
class Wheel
{
public:
int pressure = 0;
int inflate(int psi)
{
pressure = pressure + psi;
}
};
int main()
{
//What would I have to put here or anywhere else to increase the pressure of a car object's FIRST tire's pressure - Car car1; car1.tires[0].inflate(10); (this doesn't seem to work)
}
#include <iostream>
#include <vector>
using namespace std;
class Vehicle
{
virtual void print() = 0;
};
class Car : public Vehicle
{
virtual void print();
Car(Wheel wheel[4])
{
}
};
class Wheel
{
public:
int pressure = 0;
int inflate(int psi)
{
pressure = pressure + psi;
}
};
int main()
{
Car car1(Wheel wheel[4]);
//I still don't know what I could add here that would inflate the first tire
}