Saw the following code in the project:
class Base
{
...
virtual double Function(int i) const;
...
};
class SubClass : public Base
{
virtual double Function(int i) const;
double Function(std::vector<int> vecInts) const;
double Function(std::map<int> mapInts) const;
};
I don't feel comfortable about this design. I knew we should avoid overload virtual functions but here the case is a little different.
Question> Is there a design flaw here?
Thank you
Nope, it's okay. Overloading virtual
functions is fine. Hiding virtual functions is what you should be cautious about.
In your case, you're overriding the base version and providing two more overloads. So no hiding occurs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With