how to count the number of objects created in c++
pls explain with a simple example
template
class Counter
{
private:
static int count;
public:
Counter()
{
count++;
}
Counter(const Counter &c)
{
count++;
}
~Counter()
{
count--;
}
static int GetCount() {
return count;
}
}
template
int Counter::count = 0;
class MyClass : private Counter
{
public:
using Counter::GetCount;
}
This technique is called CRTP