bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_2 / eduincs / pgrm_019.cpp

pgrm_019.cpp (548B)


      1 /* Overload `++` when used as prefix */
      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 ++() {
     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 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror