Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ Language Reference - invoking a virtual function http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
   Invoking a Virtual Function
   A  virtual function is invoked through a pointer or a reference  of  a
   particular  class type. The actual function invoked is  determined  by
   the  class  type  of the actual object addressed  by  the  pointer  or
   reference. Since a pointer or reference to a base class can be used to
   address  an object of a derived class the function invoked may not  be
   that defined for the class type of the pointer or reference.

   The  syntax for calling a virtual function is the same as that  for  a
   regular  member  function.  The  call through  a  pointer  is  handled
   automatically.

   If a pointer or reference to an abstract class at the top of the class
   hierarchy is used, the pointer or reference can be used to address  an
   object  of  any  class  type in  the  hierarchy  and,  therefore,  any
   redefinition  of the virtual function may be invoked by assigning  the
   address  (or  lvalue)  of the appropriate object  to  the  pointer  or
   reference.

   If the virtual function is invoked through a class object it is always
   resolved  statically (at compile time) to the instance of the  virtual
   function which is defined or defaulted for that object of that class.

   A particular instance of a virtual function can be explicitly  invoked
   by means of the class resolution operator: classname::

   If a virtual function is invoked by a base class constructor, the base
   class  instance is always invoked since the derived class  object  has
   not  yet  been created, except that where the base class is  itself  a
   derived  class it may call a virtual function and expect it to  behave
   reasonably  for  those  classes  which  are  above  it  in  the  class
   hierarchy.


Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson