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;

public:

SI(){};

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
Prepare an iPad application Clash of Clans like game I would like to prepare a free city building app with the in app purchase possibility. An example game could be Clash of Cla


write a class player that contain attributes for the player,s name,average and team

A: Method of passing arguments to a function that takes parameter of type reference.  for instance: void swap( int & x, int &amp;amp; y ) { int temp = x; x =

Write a program to find minimum number of shelves

I need to include files so you can understand easier.

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Need help finishing my homework. It''s been 5 years since I''ve use C++. I am a VN.Net programmer. -Todd

In this Lab you will code 8086 assembler equivalents (Virgo) for common C control flow instructions. This will give you an appreciation for how control flow is implemented in assem

I. COURSE DESCRIPTION Develops a working knowledge of object-oriented concepts in areas of classes, inheritance, data structures, error handling, templates and file processing.