FAQ 21.02 What is a virtual member function?

A virtual member function is a member function preceded by the keyword virtual or a member function with the same signature as a virtual function declared in a base class.

In this context, virtual means "overridable." More specifically, the keyword virtual means that the runtime system automatically invokes the proper member function when it is overridden by a derived class (dynamic binding).

A member function should be made virtual when there will be derived classes that will need to provide their own implementation for the member function. This doesn't require as much clairvoyance as it seems to imply. Normally the virtual functions represent specifically architected places where extensibility is supposed to take place.

Overriding a virtual member function is also straightforward: simply declare the member function in the derived class and define a new implementation for that member function.



C++ FAQs
C Programming FAQs: Frequently Asked Questions
ISBN: 0201845199
EAN: 2147483647
Year: 2005
Pages: 566
Authors: Steve Summit

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net