Following the revelation that it did indeed work, Christian based the entire ATL and Windows Template Library (WTL) design on this mistake.
[citation needed] Some use cases for this pattern are static polymorphism and other metaprogramming techniques such as those described by Andrei Alexandrescu in Modern C++ Design.
This technique achieves a similar effect to the use of virtual functions, without the costs (and some flexibility) of dynamic polymorphism.
This effectively emulates the virtual function call system at compile time without the costs in size or function call overhead (VTBL structures, and method lookups, multiple-inheritance VTBL machinery) at the disadvantage of not being able to make this choice at runtime.
Each method returns an object, allowing the calls to be chained together in a single statement without requiring variables to store the intermediate results.
A commonly used idiom for this is adding a virtual clone function that is defined in every derived class.
This allows obtaining copies of squares, circles or any other shapes by shapePtr->clone().
Since the self parameter is automatically deduced as the correct derived type, no casting is required.