Why is a pure virtual function initialized by 0?

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.

Leave a Comment