Curiously recurring template pattern: Difference between revisions

Content deleted Content added
No edit summary
trivial missing word
Line 38:
To elaborate on the above example, consider a base class with '''no virtual functions'''. Whenever the base class calls another member function, it will always call its own base class functions. When we inherit from this class, a derived class, we inherit all the member variables and member functions that weren't overridden (no constructors or destructors, of course, either). If the derived class calls an inherited function that then calls another member function, it will never call any derived member functions. As a result of this behaviour, most C++ programmers define member functions as virtual to avoid this problem. Unfortunately, this can't be applied to static functions.
 
However, if base class member functions use the CRTP pattern for all member function calls, the overridden functions in the derived class will get selected at compile time. 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) and the slight disadvantage of not being able to do this choice at runtime.
 
==See also==