Home | Computer Science

<
Operator Overloading

Defination

A compile-time polymorphism in which the operator is overloaded to provide the special meaning to the user-defined data type.


FUNCTION OVERLOADING
Basic Program
INPUT

#include<iostream.h> #include<conio.h> class sample { private: int x; float y; public: sample(int,float); void display(); }; sample::sample(int one,float two) { x=one; y=two; } void sample::display() { cout<<"integer number(x)=:"<<x<<endl; cout<<"floating number(y)=:"<<y<<endl; cout<<endl; } void main() { clrscr(); sample obj1(10,12.123); sample obj2(20,30.123); obj2=obj1; cout<<"first object \n"; obj1.display(); cout<<"second object \n"; obj2.display(); getch(); }

OUTPUT