hello, i'm trying to write two classes (vehicle and driver)
first i want to create the class vehicle and it's attrbutes, but there is a problem when i compile the code.
please see all my code
#include<iostream>
#include<vector>
using namespace std;
//
// Vehicle: Vehicle number, type, capacity, driver assigned
class Vehicle{
int id;
public:
Vehicle(int id) : id(id) {
cout <<"Vehicle created successfully" << endl;
id++;
}
int getID() const { return id; }
};
class VehicleType : public Vehicle{
string name;
int capacity;
string driver_assigned;
public:
VehicleType(int id,string name,int capacity, string driver_assigned)
: Vehicle(id), name(name), capacity(capacity), driver_assigned(driver_assigned){
}
void getVehicleType(){
cout <<"id: " << getID()
<<"name: " << name
<<"capacity: " << capacity << endl;
}
};
int main(){
vector<Vehicle*> vehicles;
int id,capacity;
string name,driver_assigned;
cout <<"Please enter the name of vehicle type: ";
cin >> name;
cout <<"Please enter the capacity of vehicle type: ";
cin >> capacity;
Vehicle *abc = new VehicleType(id,name,capacity,driver_assigned);
vehicles.push_back(abc);
for (int i = 0; i < vehicles.size(); i++)
{
cout <<"id "<< vehicles[i]->getID() <<endl;
cout <<"id "<< vehicles[i]->getVehicleType() <<endl;
}
return 0;
}
the error is in line 48, i'm trying to output all varibles by using getVehicleType function
what is my mstake?
also i want the vehicle id increase when create a new vehicle and decrease when i delete vehivle, i try to do so but i get error
thank you