#include <iostream>
using namespace std;
class Counter
{
private:
unsigned int count;
public:
Counter() : count(0)
{
cout << "Constructor called " << endl;
}
~Counter()
{
cout << "Destructor called " << endl;
}
unsigned int get_count()
{
return count;
}
Counter operator ++ ()
{
++count;
Counter temp;
temp.count = count;
return temp;
}
};
int main()
{
Counter c1, c2;
cout << "\nc1=" << c1.get_count();
cout << "\nc2=" << c2.get_count();
++c1;
c2 = ++c1;
cout << "\nc1=" << c1.get_count();
cout << "\nc2=" << c2.get_count() << endl;
return 0;
}
Constructor called Constructor called c1=0 c2=0Constructor called //constructor of Counter temp Destructor called //destructor of Counter temp Destructor called //what destructor does this belong to? Constructor called //constructor of Counter temp Destructor called //destructor of Counter temp Destructor called //same question here? c1=2 c2=2