Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: C++
Expertise: All
Jun 4, 1998



Application Security Testing: An Integral Part of DevOps

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 {
FILE *pf;
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.
			//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


Danny Kalev
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date