bsc

Comprehensive codebase and coursework for the 4-year B.Sc. Computer Science Honours degree (WBSU)

git clone https://github.com/notamitgamer/bsc.git
· rebuilt hourlyOpen on GitHub
root / semester_2 / eduincs / pgrm_020.cpp

pgrm_020.cpp (552B)


      1 /* Overload `++` when used as postfix */
      2 
      3 #include<iostream>
      4 using namespace std;
      5 class count {
      6 private: 
      7     int val1;
      8     int val2;
      9 public: 
     10     count() {
     11         val1 = 5;
     12         val2 = 6;
     13     }
     14 
     15     void operator ++(int) {
     16         val1++;
     17         val2++;
     18     }
     19 
     20     void display() {
     21         cout << "value1: " << val1 << "  value2: " << val2 << endl;
     22     }
     23 };
     24 
     25 int main() {
     26     count obj;
     27     cout << "Before overloading ++: " << endl;
     28     obj.display();
     29     obj++;
     30     cout << "After overloading ++: " << endl;
     31     obj.display();
     32     return 0;
     33 }