Thread: virtual or pure virtual

  1. #1
    Unregistered
    Guest

    Arrow virtual or pure virtual

    Hi, can anyone tell the rules of declaring a function virtual or pure virtual?

    The derived class will need to declare the inherited function as virtual if the same function is pure virtual in the base class. Is this right?

    How about when writing an abstract base class? I'm confused about pure virtual and virtual here.

    Thanks.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    You use a PURE virtual function when you only want to specify an interface and do not need a default implementation of that function.Any class that has a pure virtual function is an ADT. You cannot instantiate objects of this type yet you may use pointers or references to it. This makes it a class that is purely to be inherited from.Any class derived from this class that does not provide an implementation for this function automatically becomes an ADT.

    You use an IMPURE virtual function when you want to specify an interface and also a default implementation. This way you can instantiate objects of the class.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-28-2009, 09:25 AM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. errors initializing D3D
    By Vacation Guy in forum C++ Programming
    Replies: 3
    Last Post: 08-07-2005, 12:20 PM
  4. Information Regarding Pure Virtual Functions
    By shiv_tech_quest in forum C++ Programming
    Replies: 6
    Last Post: 01-29-2003, 04:43 AM
  5. C++ XML Class
    By edwardtisdale in forum C++ Programming
    Replies: 0
    Last Post: 12-10-2001, 11:14 PM