I am tasked to have a class C
which automatically keeps track of the number of its instances that exists, and to have a function that returns this number.
Here is what I have:
class C{
public:
static int num;
C(){++num;}
~C(){--num;}
int get_number_objs(){return num;}
};
int C::num = 0;
Does this do the trick?
This looks straightforward and might make sense, but I'm wondering if there are edge cases where you mess around with pointers or something like that where something falls through the cracks.
This is a solution verification more than anything else.