Thread: virtual prototype in a class

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    13

    virtual prototype in a class

    Hello
    I have this base class:

    Code:
    1. class base
    2. {
    3. private:
    4. .....
    5. public:
    6. ....
    7. virtual void test() = 0:
    8. }
    My questions:
    1. Why i be force to write "= 0" in line seven
    2. It's with line seven a pure abstract class so i can't create a object of the base class. But why it's a pure abstract class?

    regards

    sphreak

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You don't have to write '= 0', but doing so makes it a pure virtual class which you can't create objects from (without inheriting from it).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    13
    hmm...
    so it haven't some reason because of memory managment or other reason?
    the compiler know it when there is a line how this in the class, that the class is a pure virtual class?

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    If you don't put the =0 there the linker will search for an implementation of the method and, failing to find one, refuse to link the app.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. resolving virtual class for Queue?
    By bean66 in forum C++ Programming
    Replies: 3
    Last Post: 05-01-2009, 11:01 AM
  2. Inherite nonvirtual class functionality
    By DrSnuggles in forum C++ Programming
    Replies: 2
    Last Post: 04-30-2009, 01:52 PM
  3. Declaring instances of different implementations
    By dwks in forum C++ Programming
    Replies: 8
    Last Post: 07-16-2008, 11:43 AM
  4. class template Prototype?
    By Aidman in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2004, 03:37 PM
  5. Virtual Functions
    By guda in forum C++ Programming
    Replies: 3
    Last Post: 11-16-2004, 04:13 PM