-1

See Object counter example here: Why it just does not inherit from non-template class counter. Why counter should be template?

template <typename T>
struct counter
skypjack
  • 49,335
  • 19
  • 95
  • 187
Narek
  • 38,779
  • 79
  • 233
  • 389

1 Answers1

6

Specializations will give you different counters for different types.
Note that those counters are static data members, thus shared among all instances of the given specialization.

skypjack
  • 49,335
  • 19
  • 95
  • 187
  • 1
    aaaahh, those counters are static, right? stupid question :D – Narek May 30 '16 at 17:06
  • 1
    @Narek Each question seems stupid once answered. ;-) – skypjack May 30 '16 at 17:15
  • @skypjack _"Each question seems stupid once answered"_ Well, there is blatant stupid stuff sometimes, and you should seriously prefix your answer with a disclaimer to get on a _forehead protection_ before reading further. The OP will tend to heavily injury themselves banging their head against a wall or just the desktop in front. – πάντα ῥεῖ May 30 '16 at 17:20
  • @πάνταῥεῖ Hope you are not over-excited about this question, dear blatant ;) – Narek May 30 '16 at 17:25
  • @skypjack I'm not even sure, if the OP might sue you for such injuries in the U.S., because you forgot to give the warning. They have a weird legislative system. ;-) – πάντα ῥεῖ May 30 '16 at 17:26
  • Popcorn and beer sounds good. It's almost 8PM in Italy. What about a good movie to watch meanwhile? :-D – skypjack May 30 '16 at 17:30
  • 1
    @skypjack _"What about a good movie to watch meanwhile?"_ _Big Bang Theory_ is running sideways on the big plasma TV :-D ... – πάντα ῥεῖ May 30 '16 at 17:31
  • 1
    You win. That's all. We are to be banned from SO, but it was worth it. ;-) – skypjack May 30 '16 at 17:36
  • 1
    Of course it was worth the fun. I think that @Narek will get over my downvote, and you will enjoy my upvote. I'm pretty sure none of us will get banned about this funny Q&A pair. – πάντα ῥεῖ May 30 '16 at 17:41
  • 1
    We still can do something to get banned. Seams we make here a FB. LinkedIn has become FB now it is time of Stackoverflow. GitHub is the next :D – Narek May 31 '16 at 04:01