KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've seen it stated that C++ has name hiding for the purposes of reducing the fragile base class problem. However, I definitely don't see how this helps. If the base class introduces a function or overload that previously did not exist, it might conflict with those introduced by the derived class, or unqualified calls to global functions or member functions- but what I don't see is how this is different for overloads. Why should overloads of virtual functions be treated differently to, well, any other function? Edit: Let me show you a little more what I'm talking about. struct base { virtual void foo(); virtual void foo(int); virtual void bar(); virtual ~base(); }; struct derived : base { virtual void foo(); }; int main() { derived d; d.foo(1); // Error- foo(int) is hidden d.bar(); // Fine- calls base::bar() } Here, foo(int) is treated differently to bar() , because it's an overload.
Tags (comma-separated)
Save Edits
Cancel