The =0
marker instructs the compiler that no member function implementation is provided anywhere, and that derived classes of which objects are to be created must implement (i.e., override) it. (Of course, the compiler only checks whether an overriding function is declared in the derived class definition; the compiler cannot check whether an actual implementation is present in one of the many other translation units.)
This has two implications.
Code trying to instantiate a derived class which does not declare an override for a pure virtual base class function is rejected at compile time. If the base class member function declaration was missing the
=0
, the compiler would assume that the base class function definition is provided in another translation unit (vulgo: file) and simply compile the code using a derived class without an override. That the base class function definition is actually lacking would still pop up but only at link time which is annoying (imagine you are programming a library and the error only pops up at the customer's site when they try to use it).Even if that base class definition of a "normal" virtual base class member function is never used (for example because only derived types that override it are ever instantiated), it is still required by the linker to be present. (There is not really a material reason for that, except that apparently the programmer meant one to be there). For a pure virtual function, no definition needs to be (and none can be) provided.
Apart from these implications on the language level, a pure virtual function indicates intent. It is a feature of the language, like override
, that increases the expressiveness available to the programmer, with some minor language support.