Thread: pure virtual function

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    3

    Exclamation pure virtual function

    what is a pure virtual function in c++?
    how to use of a pure virtual function and when?
    what kind of a special significance does a pure virtual function have and why doest it said to exhibit run time polymorphism??

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    In a class declaration, 'virtual ret_type f(args ...) = 0;' is a pure virtual function (as denoted by the = 0). These make the class an abstract data type which cannot be instantiated, and therefore, force all derived classes (which are not intended to be ADTs themselves) to override this function. You can have pointers to this base class, however, so you can use the polymorphic behavior as normal.

    They are good to use when all derived classes should have the specified function(s) (hence virtual), and when there is no way to implement it in a generic enough way in the base class for use by any derived class.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. What is a virtual function pointer?
    By ting in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2008, 02:36 AM
  3. Replies: 39
    Last Post: 11-30-2007, 02:16 AM
  4. Stroustrup Talk on C++0x
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 07-20-2007, 02:02 AM
  5. runtime error R6025 - pure virtual function call
    By nvoigt in forum Windows Programming
    Replies: 3
    Last Post: 07-11-2004, 12:50 AM