mercredi 12 décembre 2018

Inheriting pure virtual methods with different arguments in different derived classes

I've declared a pure virtual method in the base class, but I want to make set of arguments in different derived classes to be different.

My current code is overloading functions in base class, which goes like:

class Base {
protected:
    virtual void function(arg_set_first) = 0;
    virtual void function(arg_set_second) = 0;
}

class Derived_First: public Base {
private:
    void function(arg_set_first);
    void function(arg_set_second) = { }; // do nothing
}

class Derived_Second: public Base {
private:
    void function(arg_set_first) = { }; // do nothing
    void function(arg_set_second);
}

It works but I think it's ugly, as there are redundant implementations in each derived class. I want to remove them.

How can I change the pure virtual function in the base class to have variable set of arguments which would be specified when is implemented? Is there a way to do so?

Aucun commentaire:

Enregistrer un commentaire