I'm new to C++ and I'm trying to write a CarRental class which contains a vector of pointers to a base class Car. Here's the Car class.
class Car{
public:
Car():mPlate(""), mBrand(""){}//constructor
Car(string p, string b): mPlate(p), mBrand(b){} //constructor
virtual ~Car(){}//destructor
const string plate() const;
const string brand() const;
virtual int numPassengers() = 0;
protected:
string mPlate;
string mBrand;
};
const string Car::plate() const{
return mPlate;
}
const string Car::brand() const{
return mBrand;
};
And I need to write a class CarRental which contains the container to store the cars. For example,
class CarRental{
public:
CarRental(vector<Car*> cars){mCars = cars;};
const vector<Car*>& getCars() const;
void addCar(Car*);
private:
vector<Car*> mCars;
};
const vector<Car*>& CarRental::getCars() const{
return mCars;
}
void CarRental::addCar(Car* c){
mCars.push_back(c);
}
I doubt whether the class of CarRental I wrote in the right way. I'm considering if I need to write my own copy constructor. And by THE BIG THREE, should I also need assignment operator and destructor? Would three be any memory leaks? How about exception safety?