Curiously recurring template pattern: Difference between revisions

Content deleted Content added
inline references
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.
Line 88:
</source>
 
Each time an object of class <code>X</code> is created, the constructor of <code>counter<X></code> is called, incrementing both the created and alive count. Each time an object of class <code>X</code> is destroyed, the alive count is decremented. InIt thisis example,important noneto ofnote thethat functionality<code>counter<X></code> inand the<code>counter<Y></code> templateare usestwo theseparate template parameter,classes and itthis is onlywhy usedthey aswill akeep wayseparate of creating different static counters for different classes. Remember that each instantiationcounts of a template with a type argument is a class of itself, and thus the static counter attributes in the <code>counterX</code>'s template are different offering separated counters forand <code>XY</code>'s. andAlso note that <code>Ycounter<T></code> classesdoes not necessarily use the type in this example, except to keep the counts separate.
 
==In other languages==