Content deleted Content added
→Object counter: Changed the wording to how I felt was clearer. Wanted "but how does it keep the counts separate?" answered ASAP, but though the first sentence was too soon. |
m Bot: Converting bare references, using ref names to avoid duplicates, see FAQ |
||
Line 47:
</source>
This technique achieves a similar effect to the use of virtual functions, without the costs (and some flexibility) of dynamic polymorphism. This particular use of the CRTP has been called "simulated dynamic binding" by some<ref>[http://www.pnotepad.org/devlog/archives/000083.html PN Devlog: Simulated Dynamic Binding<!-- Bot generated title -->]</ref>. This pattern is used extensively in the Windows [[Active Template Library|ATL]] and [[WTL]] libraries.
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, that function will never call any derived or overridden member functions in the derived class. As a result of this behavior, most C++ programmers define member functions as virtual to avoid this problem.
|