What''s the deal along with operator overloading?, C/C++ Programming

A: It let you to provide an intuitive interface to users of your class, as well as makes it possible for templates to equally work well with classes and built-in/intrinsic types.

Operator overloading let C/C++ operators to have user-defined meanings on user-defined types (classes). Overloaded operators are syntactic sugar for function calls:

class Fred {                      

public:

...

};

#if 0

// Without operator overloading:

Fred add(const Fred& x, const Fred& y); Fred mul(const Fred& x, const Fred& y);

Fred f(const Fred& a, const Fred& b, const Fred& c)

{

return add(add(mul(a,b), mul(b,c)), mul(c,a)); // Yuk...

}

#else

// With operator overloading:

Fred operator+ (const Fred& x, const Fred& y); Fred operator* (const Fred& x, const Fred& y);

Fred f(const Fred& a, const Fred& b, const Fred& c)

{

return a*b + b*c + c*a;

}

#endif

 

Posted Date: 3/20/2013 3:43:07 AM | Location : United States







Related Discussions:- What''s the deal along with operator overloading?, Assignment Help, Ask Question on What''s the deal along with operator overloading?, Get Answer, Expert's Help, What''s the deal along with operator overloading? Discussions

Write discussion on What''s the deal along with operator overloading?
Your posts are moderated
Related Questions
a program to find the area under curve y=f(x) between x=a and x=b,integrate y=f(x) between the limits of a and b.

Question 1 Explain the following Object Oriented Concepts with suitable examples for each Question 2 Explain the following Object Oriented Methodologies Question 3 Descr

develop a program read the following information from the keyboard in which base class consist of employee name code and destingnation the derived class contain the data members th

Based on the automobile's model year and weight, the city of Cebu determines the car's weight class and registration fee using the following schedule: Model Year Registration

replace character into string and return value of string that are replaced

Project Description: I have a barber salon I am seeking someone to build me software for my PARTNER PT6910 touch screen till system. This software must add multiple staff login

how we use the cin command and why we use this command????

Pure Virtual Functions An abstract class is one, which is used just for deriving some other classes. No object of this class is declared and used in the program. Likewise, ther

C Program for 5 FUNCTION OF VOWELS, CNT_WORDS, REVERSE void input(char a[]); void output(char a[]); void reverse(char a[], char b[]); char poli(char a[], char b[]);