I want to make a base class that helps me store some info about the class itself. One of these variables is a instance counter. It counts the instances of the classes.
Normally I would just use a static member variable, that I increase when the base constructor is called and decreased when the base destructor is called. Problem being that static member variables dont get re-created for each derived class. Instead the access is inherited, making it not a individual counter but one that simply counts the amount of base classes inherited. That is not my goal.
What I want:
- The counter should work without having to do anything in the derived class other than deriving from base
- The method shouldnt require much processing power or memory.
What I have tried:
- Using a static member (failed obviously)
- Using a normal member (failed obviously, was clear from the start)
What is the proper way to do this sort of thing.