First of all, your garage class holds a vector of Cars, not a vector of pointers to cars as you wanted. You can fix this easily by changing:
1 2 3 4 5 6 7
|
std::vector<Car>Garage;
//to
std::vector<Car*>Garage;
//and
Garage.push_back(*brum);
//to
Garage.push_back(brum);
|
Your size is fine, though push_back should work fine, why didn't it work?
Moving a car from one garage to the other shouldn't be difficult either, but you have to keep in mind that you will always move the last car of a garage or you will have to specify an index. A possible implementation could be (I specified an index):
1 2 3 4 5 6 7 8 9 10 11
|
void moveCar(int index, Garage destination)
{
if (index > Garage.size()-1) //-1 because max index of a garage with 5 cars is 4
{
std::cout << "Error, car not found!\n"; //throw an error
return;
}
Car temp = Garage[i]; //create a temporary copy of the car
Garage.erase(i,1); //erases 1 element from the garage, starting from index i;
destination.add(&temp); //add the car to destination garage
}
|
To use this just do the following in your main function:
|
garage[0].moveCar(1,garage[1]);
|
This moves the car at index 1 from garage 0 to garage 1.
For the borrowing, you could make moveCar return an integer, the last index of the destination garage, when you can can just call moveCar again with that return value as index to be moved.
I hope this answers all your questions.