Search code examples
c++pure-virtual

What does `= 0` mean in the decalartion of a pure virtual function?


Possible Duplicates:
C++ Virtual/Pure Virtual Explained
What's the difference between virtual function instantiations in c++
Why pure virtual function is initialized by 0?

This is a method in some class declaration that someone gave me. And I don't know what '..=0' means. What is it?

virtual void Print() const = 0;

Solution

  • The = 0 makes the function pure virtual, rendering the class an abstract class.

    An abstract class basically is a kind of interface, which derived classes need to implement in order to be instantiable. However, there's much more to this, and it is some of the very basics of object-oriented programming in C++. If you don't know these, you need to go back to the textbook and read up. There's no way you can advance without understanding them.

    That said, see this related question for some explanations of what virtual and pure virtual functions are. And as always, the C++ FAQ is an excellent resource for such questions.