Question

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;
Was it helpful?

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.

OTHER TIPS

It means that the virtual function is pure, meaning that you cannot call it as such: the function doesn't have any code to it, hence the = 0. Only by deriving the class and overriding the function you can call it. The class with pure virtual functions cannot be instantiated so they are called abstract classes, interfaces in some languages.

Basically, it means the function has no code. This means that you cannot use instances of this class. Rather, it can only be a base class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top