Overloaded functions

#include<<iostream.h>

class Complex {
public:
   int v1, v2;
};

class C {
   int val;
public:
   int greater(int v1);
   int greater(Complex * C1);
   int get_val();
   C(int init);
};

int C::greater(int v1) {
   if(v1>val) val=v1;
   return val;
}

int C::greater(Complex * C1) {
   if(C1->v1>val) return(val=C1->v1);
   return val;
}

int C::get_val() { return val; }

C::C(int init) { val=init; }

int main() 
{
   Complex * Com=new Complex;
   C * C1 = new C(3);
   Com->v1 = 5; Com->v2 =4;
   cout<greater(4) << " " << C1->greater(Com) << '\n';
   return 0;
}
Plain text version to compile and run.

Functions are different if they have different numbers or types of arguments. Back to overloading note

Back to index