/* Lecture code 8.2
 *
 * Advanced C++: The Curiously Recurring Template Pattern (CRTP)
 */

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
using namespace std;

/* A class that counts the number of instances of an active class.  Counter is a template class, but it doesn't use
 * the template parameter anywhere.  It's just to give each class its own unique copy.
 */
template<typename T>
class Counter
{
public:
	Counter()
	{
		numInstances++;
	}
	~Counter()
	{
		numInstances--;
	}

	static int getNumInstances()
	{
		return numInstances;
	}
private:
	static int numInstances;
};

/* Needed for the static member functions. */
template<typename T> int Counter<T>::numInstances = 0;

/* This class has instance counting. */
class MyClass: public Counter<MyClass>
{

};

/* So does this one. */
class MyClass2: public Counter<MyClass2>
{

};