Page 152 - DCAP404 _Object Oriented Programming
P. 152

Unit 7: Operator Overloading




          };                                                                                    Notes
          integer::integer()
          {
                 val  =  0;

          }
          integer::integer(int  one)
          {

                 val  =  one;
          }
          integer  integer::operator+  (integer  objb)
          {
                 integer  objsum;

                 objsum.val  =  val  +  objb.val;
                 return  (objsum);
          }

          void  integer::disp()
          {
                 cout<<  “value  =”<<  val<<  endl;
          }
          void  main()

          {
                 integer  obj1(11);
                 integer  obj2(22);

                 integer  objsum;
                 objsum  =  objl  +  obj2;
                 obj1.disp();
                 obj2.disp();
                 objsum.disp();

                 getch();
          }
          You should see the following output.

          value = 11
          value = 22
          value = 33






                                           LOVELY PROFESSIONAL UNIVERSITY                                   145
   147   148   149   150   151   152   153   154   155   156   157