Pure Virtual Function in C++

Dear All,
Here I want to know why we put =0 in case of pure virtual function, why not =1, =2 or any thing else
Please send me answer any one as soon as possible.

History. :slight_smile:

If I have a function pointer in C

typedef int (*foo_ptr)(void);
foo_ptr my_foo;

I can either

(a) leave it to be undefined and a danger to all who touch it

(b) set it to point to an implementation of foo()

(c) set it to NULL or (foo_ptr)0 so people can check it's validity.

C++ is derived from C and setting it to 0 is an indication that this class does not provide an implementation of this function.

There are other places where a non-zero initialisation of a pointer is special such as the SIG_IGN/SIG_DFL and _XtInherit.

Unless you are either (a) implementing a C++ compiler (b) answering a homework question, the reason why is not actually important.