#include<iostream>
using namespace std;
class Test
{
public:
Test() {
count++;
};
~Test() {
count--;
};
static int getcount(void) {
return count;
}
private:
static int count;
};
int Test::count = 0;
int main(void) {
cout << Test::getcount() << " Object exist !" << endl;
Test test1;
cout << Test::getcount() << " Object exist !" << endl;
Test* test2 = new Test;
cout << Test::getcount() << " Object exist !" << endl;
delete test2;
cout << Test::getcount() << " Object exist !" << endl;
return 0;
}
/*
0 Object exist !
1 Object exist !
2 Object exist !
1 Object exist !
*/
02-26
3万+