void

virtual

The virtual function specifier creates a virtual function. A virtual function is a member of a base class that can be overridden by a derived class. If the function is not overridden by a derived class, the base class’ definition is used.

A pure virtual function is a member function that has no definition. This means that a pure virtual function must be overridden in a derived class. A pure virtual function is prototyped like this:

virtual ret-type fname(param-list) = 0;

Here, ret-type is the return type of the function, fname is the function’s name, and param-list specifies any parameters. The important feature is the = 0. This tells the compiler that the virtual function has no definition relative to the base class.

Runtime polymorphism is attained when virtual functions are accessed through a base class pointer. When this is done, the type of object pointed to determines which version of the virtual function is called.




C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539

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