Answers for "operator ++ counter class program"

0

operator ++ counter class program

#include <iostream>
using namespace std;

class Check
{
  private:
    int i;
  public:
    Check(): i(0) {  }

    // Return type is Check
    Check operator ++()
    {
       Check temp;
       ++i;
       temp.i = i;

       return temp;
    }

    void Display()
    { cout << "i = " << i << endl; }
};

int main()
{
    Check obj, obj1;
    obj.Display();
    obj1.Display();

    obj1 = ++obj;

    obj.Display();
    obj1.Display();

    return 0;
}
Posted by: Guest on May-25-2021

Browse Popular Code Answers by Language