// This program will be discussed in the Project section. It provides a
// demonstration of static methods and variables.

#include <iostream>

// The Demo class keeps track of how many objects of that class exist at the
// present time.
class Demo {
public:
    Demo();
    ~Demo();
    static int num_live();
private:
    static int live_objects;
};

int Demo::live_objects = 0;

Demo::Demo()
{
    live_objects++;
}

Demo::~Demo()
{
    live_objects--;
}

int Demo::num_live()
{
    return live_objects;
}

int main(int argc, char **argv)
{
    std::cout << "Initial number of live objects: " << Demo::num_live()
            << std::endl;
    
    Demo *d1 = new Demo();
    Demo *d2 = new Demo();
    Demo *d3 = new Demo();
    
    std::cout << "New number of live objects: " << Demo::num_live()
            << std::endl;
    
    delete d2;
    delete d3;
    
    std::cout << "Live objects after deleting 2: " << Demo::num_live()
            << std::endl;
    
    delete d1;
}
