views:

136

answers:

3

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;
+7  A: 

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.

sbi
+3  A: 

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.

progo
+1  A: 

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.

Alexander Rafferty
Not quite true. It means the function has no code that can be called "by default"--derived classes are require to override it, but are permitted to call a definition provided by the base class.
Drew Hall