Object Counter
The main purpose of an object counter is retrieving statistics of object creation and destruction for a given class. This can be easily solved using CRTP:
templateEach time an object of class X is created, the constructor of counter is called, incrementing both the created and alive count. Each time an object of class X is destroyed, the alive count is decremented. It is important to note that counter and counter are two separate classes and this is why they will keep separate counts of X's and Y's. In this example of CRTP, this distinction of classes is the only use of the template parameter (T in counter) and the reason why we cannot use a simple un-templated base class.
Read more about this topic: Curiously Recurring Template Pattern
Famous quotes containing the words object and/or counter:
“Among all the modernized aspects of the most luxurious of industries, the model, a vestige of voluptuous barbarianism, is like some plunder-laden prey. She is the object of unbridled regard, a living bait, the passive realization of an ideal.... No other female occupation contains such potent impulses to moral disintegration as this one, applying as it does the outward signs of riches to a poor and beautiful girl.”
—Colette [Sidonie Gabrielle Colette] (18731954)
“Often, when there is a conflict between parent and child, at its very hub is an expectation that the child should be acting differently. Sometimes these expectations run counter what is known about childrens growth. They stem from remembering oneself, but usually at a slightly older age.”
—Ellen Galinsky (20th century)