Hi!
I am making a project about doublepointers and inheritance. Have some small issues that should not be difficult to resolve, but I just cant get a grip of it.
The task is to add two types of vehicles that have some of the same characteristics but not all. I'm using a dynamic allocated array that is declared as "Vehicle ** vehicles" to store all vehicles. This is a pointer that points to another pointer and this together with inheritance immediately becomes complicated (for me).
- My questions now is how I'm going to just show all the cars and not all vehicles.?
- It should also be possible that, from a vehicle, find out if it contains a certain character combinations in number and * is used to "fill" the positions of the registration number as we do not know the contents of (for example to search for all vehicles with registration begins at A and the last digits is 19 out of character sequence A *** 19.
I have 5 cpp-files and 4 h-files but I only show some of it, and if that's not enough for you to help me, then I can post more of my code and maybe all if that's necessary.
This is when I add a Car.
void VehicleManager::addCar(string brand, string age, string regNr, string price, string fuel, string size)
{
if (this->count == this->capacity)
{
Vehicle **temp = new Vehicle*[this->capacity + 5];
for (int i=0; i<capacity; i++)
{
temp[i] = this->vehicles[i];
}
delete [] this->vehicles;
capacity += 5;
this->vehicles = temp;
}
this->vehicles[this->count] = new Car(brand, age, regNr, price, fuel, size);
this->count++;
}
This is when i show all the Vehicles
void VehicleManager::showAll()
{
for(int i=0; i<this->count; i++)
{
cout <<this->vehicles[i]->getBrand() <<'\t' <<this->vehicles[i]->getRegNr()<< endl;
}
}