Function overloading

 avatar
narendra
c_cpp
a month ago
522 B
2
Indexable
#include <iostream>
using namespace std;

class Sum {
      
      public:       
        void add (int x, int y){
          int sum = x + y ;
          cout<<sum<<endl;
      }
      
      void add (int x , int y , int z){
        int sum= x+y+z;
        cout<<sum<<endl;
      }
      
      void add (float x , float y){
        float sum = x+y;
        cout<<sum<<endl;
      }
          
      
    };
    


int main (){
  
  Sum s;
  s.add(2,4);
  s.add(3,6,6);
  s.add(float(2.5), float(2.5));
  
  return 0;
  };
Leave a Comment