#include <iostream>
using namespace std;
class Counter{
public:
static int created;
static int destroyed;
Counter(){
created++;
}
~Counter(){
destroyed++;
cout<<"Destroyed so far: "<<Counter::destroyed<<endl;
}
};
int Counter::created = 0;
int Counter::destroyed = 0;
int main(){
cout<<"Created so far: "<<Counter::created<<endl;
Counter c1, c2;
cout<<"Created so far: "<<Counter::created<<endl;
Counter c3;
return 0;
}
Comments
Leave a comment