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
The code contains two built-in pitfalls. First one, if it executes in a member function for an static, extern or automatic object, the program will possibly crash as soon as the de

Logical Operators We say any expression that evaluates to zero is a FALSE logic condition and that evaluating to non-zero value is a TRUE condition. Logical operators are usefu

I need help to understand and do this assignment ********************************************************* You are to insert the missing code in the C program given for combinatio

I''m trying to write a function that prints the substring if it is found in the string, and after it prints it deletes it from the string so i could print the next substring if it

how to use a pointer variable?

Create an applet that bounces a blue ball inside an applet using Thread. The ball (diameter is 10) will start at position (0,0). When the ball hits the edge of the applet, the ba

Aim: To implement a program to create, update & display account & admin record of person using display account & admin records of person using virtual base class.. Code:

Consider a group of n robots, numbered R2D1 through R2Dn, and m tasks, numbered 1 through m. Tasks can be different and robots are specialized, hence a given robot can only perform


FIT 3042 System Tools and Programming Languages Semester 1 2013 Assignment 1 An SDL video player for a custom video format Worth: 20% of final mark. Must be completed individually