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
solve mesh and nodal analysis through c/c++?

I am doing project on home stay which includes features like add homestay,search,book,delete homestay,

Implementing files in c++

write a c++ program, that finds the minimum total number of shelves, including the initial one, required for this loading process.

array itself is a pinter.explain

where to use tower of honoi?

What does it mean to declare a 1.      member function as a virtual A: (a) C++ virtual function is member function of any class, whose functionality may be over- ridden in

.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.

write a program to calculate the cuboid

C Program to check FACTORIAL   main() {             int i,j,m,fact,sum=0;           clrscr();           printf("ENTER THE NO.: ");           scanf("%d",&m);