by jimyndiku on May 1st, 2006

jimyndiku

Question

Help answer this question below.

What are the advantages of operator overloading in C++?

Answers



Answers. 5 helpful answers below.

  • by RedJohn on May 2nd, 2006

    RedJohn

    C++ allows the overloading of operators and functions. A single operator or function can be used with different classes of objects, which can simplify a program's code. Overloading allows a user to control the behaviour of an operator with both user-defined and standard classes. You could, for example, create an operator that differentiated between scalar, vector, and matrix operations or one that could handle complex math. While these examples are not particularly important to the typical user, they are very important for mathematical and engineering tasks.

    The following is copied from Borland C++ v5.02 help:

    "C++ lets you redefine the actions of most operators, so that they perform specified functions when used with objects of a particular class. As with overloaded C++ functions in general, the compiler distinguishes the different functions by noting the context of the call: the number and types of the arguments or operands.

    All the operators can be overloaded except for:
    . .* :: ?:

    The following preprocessing symbols cannot be overloaded.
    # ##

    The =, [ ], ( ), and -> operators can be overloaded only as nonstatic member functions. These operators cannot be overloaded for enum types. Any attempt to overload a global version of these operators results in a compile-time error.

    The keyword operator followed by the operator symbol is called the operator function name; it is used like a normal function name when defining the new (overloaded) action for the operator.

    A function operator called with arguments behaves like an operator working on its operands in an expression. The operator function cannot alter the number of arguments or the precedence and associativity rules applying to normal operator use."

    • Like
    • Report

    1 comment | Post one | Permalink

  • by alokipandey on November 14th, 2012

    alokipandey

     By using operator overloading we can easily access the objects to perform any operations.
     Using operator overloading we can perform different operations on the same operands.
     It makes code much more readable and you can override the conversion operators to allow your user-defined types to be converted to either built-in types or other user-defined types.
     An operator will act differently depending on the operands provided. Operator is not limited to work only with primitive Data Type.
     A main benefit of operator overloading is that it allows us to seamlessly integrate a new class type into our programming environment. This type extensibility is an important part of the power of an oops languages such as C++.

    by Alok pandey ( http://www.facebook.com/alokipandey )

    No comments. Post one | Permalink

  • by nora888 on April 26th, 2011

    nora888

    Write in not more than 5 lines the advantages and disadvantages of using Borland C++ /
    version 5.

    No comments. Post one | Permalink

  • by esterlydsl on April 26th, 2011

    esterlydsl

    C++ allows the overloading of operators and functions. A single operator or function can be used with different classes of objects, which can simplify a program's code. Overloading allows a user to control the behaviour of an operator with both user-defined and standard classes.

    No comments. Post one | Permalink

  • by nora888 on April 26th, 2011

    nora888

    Write in not more than 5 lines the advantages and disadvantages of using Borland C++ /
    version 5.

    No comments. Post one | Permalink

Want to attach an image to your answer? Click here.

Did this answer your question? If not, then ask a new question or create a poll.

You're reading What are the advantages of operator overloading in C++?

Follow us on Facebook!

Related Ads