Thread: Method Question

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    new york
    Posts
    84
    Rep Power
    13

    Question Method Question


    Code:
    virtual methodName() = 0;
    i've come across this in a book, and i'm wondering what the "= 0" bit is all about



    any insight would be greatly appreciated

    justin.dago
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    USA
    Posts
    286
    Rep Power
    13
    If this is C++, then it makes the method a pure virtual function. Any class that contains a pure virtual function cannot be instantiated; you must derive a base class in order to use it.
    Jon Sagara

    "Me fail English? That's unpossible!"
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Location
    London
    Posts
    349
    Rep Power
    13
    Remember though that declaring a method pure virtual doesn't mean that it can not have an implementation.

    Declaring it pure virtual means that the current class is abstract and that any concrete class inheriting from the surrent class must declare the function as a "normal" virtual function.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    new york
    Posts
    84
    Rep Power
    13
    the = 0 makes it a "pure" virtual function...??

    i was not aware there were different types of virtual functions????
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    USA
    Posts
    286
    Rep Power
    13
    http://msdn.microsoft.com/library/de...ion_Syntax.asp

    A pure virtual function MUST be overridden in a base class. A plain virtual function may optionally be overridden.
    Jon Sagara

    "Me fail English? That's unpossible!"
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    new york
    Posts
    84
    Rep Power
    13
    great. thanks a lot guys. i'm checking that link now. thanks again.

IMN logo majestic logo threadwatch logo seochat tools logo