Reputation: 107
I want to overload virtual function with different parameters in c++ but it doesn't work.
virtual void Draw( int nDeltaX, int nDeltaY);
virtual void Draw( int nDeltaX, int nDeltaY, bool m_bFlag);
Can you tell me the reason?
Upvotes: 3
Views: 11290
Reputation: 20993
The answer is - because that's the way C++ works. The parameters must be the same. C++11 standard says in 10.3.2:
If a virtual member function vf is declared in a class Base and in a class Derived, derived directly or indirectly from Base, a member function vf with the same name, parameter-type-list (8.3.5), cv-qualification, and refqualifier (or absence of same) as Base::vf is declared, then Derived::vf is also virtual (whether or not it is so declared) and it overrides 11 1 Base::vf.
Upvotes: 6