Design a class having the constructor and destructor functions that should display the number of objects being created or destroyed of class type
#include <iostream>
using namespace std;
class Enemy{
private:
static int created;
static int destroyed;
public:
Enemy(){
cout<<"Created: "<<++created<<endl;
}
~Enemy(){
cout<<"Destroyed: "<<++destroyed<<endl;
}
};
int Enemy::created;
int Enemy::destroyed;
int main()
{
Enemy a, b;
return 0;
}
Comments
Leave a comment