+ 1

Why function hiding is there in C++

Hi I am aware that function hiding (function from base class becomes not available as soon as I provide same name function in derived class). Why this limitation is there ?

27th Jun 2024, 10:53 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Réponses
0
https://stackoverflow.com/questions/11923890/reason-for-c-member-function-hiding https://stackoverflow.com/questions/5928535/name-hiding-and-fragile-base-problem 'Why' is an open-ended question. I can't find a definitive answer, but from the links above, I can see a lot of different reasoning why C++ made this decision. And most seems plausible. Particularly the one that propose it's an optimization mechanism to limit the lookup for matching functions up the OOP hiererarchy, which would potentially slow down or complicate the program's performance. C++ just use the child's version unless specifically instructed to keep looking, if the child class implements a 'using' or override... There are ways to work-around this limitation, either with 'using' or virtual functions and override. So it's not the end of the world...
27th Jun 2024, 11:29 AM
Bob_Li
Bob_Li - avatar
0
What I am looking for existence of limitation or not? Optimization is fine and work around is also fine. Is there any limitation or just a pure optimization.
28th Jun 2024, 3:58 AM
Ketan Lalcheta
Ketan Lalcheta - avatar