
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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.
- Related Articles
- What are the basic rules and idioms for operator overloading in C++?
- Overloading unary operator in C++?
- Overloading array index operator [] in C++
- Increment ++ and Decrement -- Operator Overloading in C++
- How to implement operator overloading in C#?
- How to use Operator Overloading in C#?
- What is overloading a unary operator in C++?
- How will you explain Python Operator Overloading?
- Why is operator overloading not supported by java?
- C++ Program to Subtract Complex Number using Operator Overloading
- Operator overloading in C++ to print contents of vector, map, pair ..
- How can we do Python operator overloading with multiple operands?
- Safety Rules for Sewing
- Rules for Java method overriding
- Rules Of Inference for Predicate Calculus
