Thursday, 14 June 2018

call operator () and Assignment operator can be overloaded C++

 // overload function call
      Distance operator()(int a, int b, int c) {
         Distance D;
         
         // just put random calculation
         D.feet = a + c + 10;
         D.inches = b + c + 100 ;
         return D;
      }

Distance D2; //object created;
D2 = D1(10, 10, 10); // invoke operator()




void operator = (const Distance &D ) { 
         feet = D.feet;
         inches = D.inches;
      }
// use assignment operator called
   D1 = D2;







No comments:

Post a Comment