5

Possible Duplicate:
Why pure virtual function is initialized by 0?

Hi all..

First off, I know that you declare a pure virtual method like this in C++:

virtual void myMethod() = 0;

.. but as I couldn't sleep last night, my nerdy head came to think if the "= 0"-part has any semantic meaning, or if it's "just" there to be able to declare purely virtual methods.

Are there any other places where this construct is used?
(And no - int v = 0; doesn't count :P )

Community
  • 1
  • 1
cwap
  • 11,087
  • 8
  • 47
  • 61
  • 3
    Duplicate of [Why pure virtual function is initialized by 0?](http://stackoverflow.com/questions/2156634/why-pure-virtual-function-is-initialized-by-0) – ypnos Nov 23 '10 at 09:46
  • 1
    Nice find. SO really needs a better search feature (Or I need to be better at using it :) ) – cwap Nov 23 '10 at 09:47
  • I wouldn't have found it if it wasn't already in my memory. Brain cache wasn't flushed yet. – ypnos Nov 23 '10 at 10:18

2 Answers2

3

It'as a virtual pure method.

That means that :

  • we don't provide the implementation (there is a way to provide one but it's not useful)
  • we want the child class to implement this method
  • we make this class impossible to instantiate : only a fully implemented child class can be
Klaim
  • 67,274
  • 36
  • 133
  • 188
0

It means that method is pure virtual. So, the subtypes must implement it. Also, it doesn't have the implementation here and the class is not instantiable.

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103