I recently came to know that in C++ pure virtual functions can optionally have a body.
What are the real-world use cases for such functions?
This question can really be confusing when learning OOD and C++. Personally, one thing constantly coming in my head was something like: If I needed a Pure Virtual function to also have an implementation, so why making it "Pure" in first place ? Why not just leaving it only "Virtual" and have derived both benefit and override the base implementation ?
The confusion comes to the fact that many developers consider the no body/implementation as the primary goal/benefit of defining a pure virtual function. This is not true! The absence of body is in most cases a logical consequence of having a pure virtual function. The main benefit of having a pure virtual function is DEFINING A CONTRACT! By defining a pure virtual function, you want to FORCE every derived to ALWAYS provide their OWN IMPLEMENTATION of the function. This "CONTRACT aspect" is very important especially if you are developing something like a public API. Making the function only virtual is not so sufficient because derivatives are no longer forced to provide their own implementation, therefore you may loose the contract aspect (this can be limiting in the case of a public API). As commonly said : "Virtual functions CAN be overrided, Pure Virtual functions MUST be overrided." And in most cases, contracts are abstract concepts so it doesn't make sense for the corresponding pure virtual functions to have any implementation.
But sometimes, and because life is weird, you may want to establish a strong contract among derivatives and also want them to somehow benefit from some default implementation while specifying their own behavior for the contract. Even if most book authors recommend to avoid getting yourself into these situations, the language needed to provide a safety net to prevent the worst! A simple virtual function wouldn't be enough since there might be risk of escaping the contract. So the solution C++ provided was to allow pure virtual functions to also be able to provide a default implementation.
The Sutter article cited above gives interesting use cases of having Pure Virtual functions with body.