Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mixing virtual function with overload regular functions?

Tags:

c++

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

like image 255
q0987 Avatar asked Jan 18 '13 16:01

q0987


1 Answers

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.

like image 173
Luchian Grigore Avatar answered Sep 27 '22 22:09

Luchian Grigore