C++ rules for overloading operators

C++ rules for overloading operators

Although it looks simple to redefine the operators, There are certain restrictions and limitations in overloading them, some of them are listed below

1. Only existing operators can be overloaded. now operators cannot be created
2. The overloaded operator must have at least one operand that is type of user defined.
3. We can’t change the basic meaning of an operator. That is to say we cannot redefine the plus(+) operator to subtract one value from the other.
4.The Overloaded operators follows the rules of the original operators. They cannot be overridden.
5 There are some operators that can’t be overloaded.
6 we can’t use friend functions to overload certain operators. however the member function can be used to overload them .
7.The unary operators, overloaded by the member function, take no explicit arguments and also no explicit values return, but those overloaded by means of a friend function, take one reference argument.
8. Binary operator overloaded through a member function take two explicit arguments
9. When using the binary operators overloaded using a member function, the left hand side operand must be an object of the relevant class.
10. Binary arithmetic operators such as *,+,- and / must be explicitly return the value, they must not attempt to change their own arguments.

OPERATORS that can not be overloaded
Sizeof size of operator
. * Membership operator
:: scope resolution operator
?: Conditional operator
Where a friend cannot be used
= assignment operator
() Function call operator
[] subscripting operator
-> class member access operator
  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise