devxlogo

Hiding a base class member function

Hiding a base class member function

A derived class may hide a member function declared in its base class by using the same function name, but with a different signature, or list of arguments. Usually, this case suggests a programmer’s mistake, especially if the hidden function is virtual. However, it can also be used as a means of hiding a base class member function when the designer of the derived class decides that any invocation of the original member function is undesirable or even dangerous:

 class B {private:FILE *pf;public: //...virtual void close(FILE *f) //may throw an exception};class D : public B { //no file I/O in D, calling B::close from                  //here is dangerous and never needed.public: 			//a 'neutralized' close, harmless    void close(int i){} //hiding B::close(), not overriding it};void f() {B b;FILE *p;//....D d;d.close(p);//compile-time error: B::close()not accessible}
See also  The Benefits of Patient Engagement Solutions for Healthcare Providers
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist