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
Write a function that has an int parameter n, makes an integer mask having the bit 1 at the nth place from the rightmost bit, and returns the mask. For example, when n = 5 is passe

Ask question #M i want to undersatnd about tree structures like node leaf etcinimum 100 words accepted#

What does ODBC do in context with PHP? PHP supports many databases such as dBase, Microsoft SQL Server, Oracle, etc. however, it also supports databases such as filePro, FrontB

Write a function that has int parameter n, makes another type of mask having n bit 1's from the left most bit and 32- n bit 0's next. The mask is called netmask in this seminar, an

How can I handle a constructor that fails?

# include stdio.h> # include string.h> # include conio.h> void main()   {           int i=0,count=0;           char a[100],b;           clrscr();

C Program for FUNCTION OF COUNT THE CHARACTERS IN EACH WORD void count(char c[]); void main() {           char a[50];           int i=0;           clrscr();

For this program you will add and test 2 new member functions to the IntSLList class posted on the website. The two member functions are: insertByPosn(int el, int pos) Assuming t

Define  T y pe c o m p a t i b i li t y? T o a s s i g n i n t t o s m a l l i n t t h e v a r i a b l e should b e

A: A smart pointer is a C++ class which mimics a regular pointer in syntax and some semantics, however it does more. Since smart pointers to distinct types of objects tend to have