We always declare a pure virtual function as:
virtual void fun () = 0 ;
I.e., it is always assigned to 0.
What I understand is that this is to initialize the vtable entry for this function to NULL and any other value here results in a compile time error. Is this understanding correct or not?
The reason =0
is used is that Bjarne Stroustrup didn't think he could get another keyword, such as "pure" past the C++ community at the time the feature was being implemented. This is described in his book, The Design & Evolution of C++, section 13.2.3:
The curious =0 syntax was chosen ... because at the time I saw no chance of getting a new keyword accepted.
He also states explicitly that this need not set the vtable entry to NULL, and that doing so is not the best way of implementing pure virtual functions.