Rules of operator overloading, C/C++ Programming

Rules of Operator Overloading

  • It is a function defined to an operator with new term or meaning.
  • It cannot produce new operator.
  • It cannot modified the meaning of the existing operator.
  • It can generate new functionality for the existing operators.
  • It helps to produce mathematical expression to replace arguments in function.
  • Binary and Unary operator overloading.
  • The following operators cannot be overloaded class member access (., .*), conditional (?:)sizeof, and scope (::).

Regular Function in a class

class SI

{float i,p,n,r,a;



SI(int gp,int gn, int gr);

void putdata(void);

SI sum(SI, SI);


SI SI::sum(SI i1, SI i2)

{SI i3; i3.p=i1.p+i2.p; i3.i=i1.i+i2.i; i3.a=i1.a+i2.a; return i3;


void SI::putdata(void)

{cout<<"Principle is: "<



SI::SI(int gp,int gn, int gr){

p=gp;n=gn;r=gr; i=(p*n*r)/100; a=p+i;


int main()

{           SI i1,i2,i3;

i1=SI(1000,2,10); i1.putdata(); cout<

return 0;


Posted Date: 9/20/2012 8:16:49 AM | Location : United States

Related Discussions:- Rules of operator overloading, Assignment Help, Ask Question on Rules of operator overloading, Get Answer, Expert's Help, Rules of operator overloading Discussions

Write discussion on Rules of operator overloading
Your posts are moderated
Related Questions
2-D Array- C program: Define a two dimension array using c. void convert ( int a[10][10] , int[] , int , int); void main()   {   clrscr();   int a[10][10], b[10

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

How can I handle a destructor that fails? Need help please provide example also.

Are comments included during compilation stage and placed in EXE file as well? - No, comments encountered by compiler are disregarded. - Their only purpose is ease and guida

Pls i only need help with program 2. #include #include using namespace std; int main() { int FilingStatus; cout cout cout cout cout cout

Write a simple program in C++ to investigate the safety of its enumeration types. Include at least 10 different operations on enumeration types that are incorrect/unsafe things to

Working Ordered linked list: • Eachinteger in the queue is stored inside of a QueueItem. The QueueItem contains the integer, and a pointer to the next item in the queue. Fo

Write a programme to display the patern.. A A B A C B A B C A B A A

The purpose of this assignment is to familiarize you with the notion of encapsulation as well as some aspects of IP and ICMP. Write your programs in C or C++. They will be grade