I have multiple derived classes which extends the same Base class. They have the same properties, with the exception of a single method that might have different arguments and body. How can I have a std::unique_ptr and call methods for the derived classes?
Here is what I know so far:
- A function template can not be
virtual
; - A pure virtual function can not be overriden with a different signature;
- A function pointer would require to know the argument list of all possible derived functions
Here is what I'm currently leaning torwards (without success):
Base class:
class IBase{ /** ... **/ template <class T, typename ...Args> MyCustomType perform(T &obj, Args ... args) { std::bind(obj->run, args); } virtual MyCustomType run(...) = 0;};
Derived class:
class Derived : IBase{ /** ... **/ virtual MyCustomType run(MyType1 a, MyType2 b, bool c) override { /* code */ }};
I wanna be able to use my pointer to the base class, call basePtr->perform(a, b, c)
and the method from subclass Derived
to be executed. Does it make any sense?