
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Rules for Operator Overloading in C++
In C++ it supports compile time polymorphism. The examples of compile time polymorphism are the function overloading and the operator overloading.
There are some rules for the operator overloading. These rules are like below
Only built-in operators can be overloaded. If some operators are not present in C++, we cannot overload them.
The arity of the operators cannot be changed
The precedence of the operators remains same.
The overloaded operator cannot hold the default parameters except function call operator “()”.
We cannot overload operators for built-in data types. At least one user defined data types must be there.
The assignment “=”, subscript “[]”, function call “()” and arrow operator “->” these operators must be defined as member functions, not the friend functions.
Some operators like assignment “=”, address “&” and comma “,” are by default overloaded.