Sunday, June 24, 2007

avoid hiding inherited names


scope a derived class is nested inside its base class's scope

only names matter for determining what gets hidden
so if u define a fn in base and same name is defined in derived than that name will hide all the names in base.

if you want to carry over all names from base , use using base::name
is this behavior same for virtual functions also ? does their signature have to be exactly same ? check on this ?

if u want to enable only a few variants from the overload, than just have a forwarding function.
how do you do this if you want to bring in a variable definition in scope ?

things to remember:
names in derived classes hide names in base classes. under public inheritance this is never desirable.
to make hidden names visible again, eploy using declarations or forwarding functions



--
Regards,
Umesh Kumar

http://worthyarticles.blogspot.com/
http://learnbooks.blogspot.com/
http://cplusplusnotes.blogspot.com/

1 comment:

Joe said...

Thanks for the informative post. Name hiding in C++ can be confusing. Also, this page is great:

Name Hiding in C++