I have a problem with code in my project. I have base class Car and two derived classes Bus and Lorry. I define pure virtual function void add() and the thing is that I want it to add either Load or Passenger depending on which class it is called in eg. when I call function void add() for Bus I want it to add an object of class Passenger. I know that it is impossible to use different parameters in derived classes and I really want to avoid using templates. How can I do this? If not everything is clear, ask me. Thank you in advance.
class Car
{
public:
friend std::ofstream& operator<<(std::ofstream&, const Car&);
friend std::ifstream& operator>>(std::ifstream&, Car&);
void view();
virtual void add() = 0;
virtual void remove() = 0;
virtual ~Car();
protected:
Car() = delete;
size_t _weight, _number_of_passengers;
std::string _name;
Engine _engine;
Passenger* _passengers = nullptr;
Load _load;
};
class Lorry : public Car
{
Lorry() = default;
size_t maximum_load;
public:
void add() override;
void remove() override;
virtual ~Lorry();
};