Create a class Index which keeps track of the Index value. Write an overloaded function to display the index value after increment and decrements the Index value.
#include <iostream>
using namespace std;
class Index
{
public:
Index();
~Index();
static void Display();
private:
static int index;
};
int Index::index = 0;
Index::Index()
{
index++;
Display();
}
Index::~Index()
{
index--;
Display();
}
void Index::Display()
{
cout << "Index current value is: " << index << endl;
}
int main()
{
Index Obj1;
Index Obj2;
Index Obj3;
cout << endl;
return 0;
}
Comments
Leave a comment