Let's say I have a base class called "Component"
class Component
{
public:
virtual void init() = 0;
};
This base class requires derived classes to define an "init" function. However, this init function declaration enforces that the function accepts no input arguments. This is not what I want.
I'm looking for a method to enforce an "init" function but allow the derived class to vary in the number of arguments it accepts.
Depending on the component type, the derived class should accept varying number of inputs.
How would this be achieved in C++?
Examples
class DerivedComponent1 : Component
{
void init(int arg1);
};
class DerivedComponent2 : Component
{
void init(int arg1, int arg2);
};
Component, how would the caller ofinitknow how many parameters to pass?