Content deleted Content added
m utilize syntax highlighting |
|||
Line 2:
==Example==
<source lang="cpp">
{
// ...▼
// ...
</source>
Typically, the base class template will take advantage of the fact that member function bodies (definitions) are not instantiated until long after their declarations, and will use members of the derived class within its own member functions, via the use of a <code>static_cast</code>, or simply a cast e.g.:
<source lang="cpp">
{
void interface()▼
void
{
// ... static void static_func()▼
{▼
▲ // ...
};▼
struct derived : base<derived>▼
{
▲ // ...
};▼
{
void implementation();
</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 [http://www.pnotepad.org/devlog/archives/000083.html some]. This pattern is used extensively in the Windows [[Active Template Library|ATL]] and [[WTL]] libraries.
|