Notes
C Plus Plus
C Plus Plus
  • Roadmap
    • 🛣️C Plus Plus: Docs
  • Build
    • 🔥Build Process
    • 🔧Connect multiple C++ Files
  • Code
    • ⏮️Pre-Processors
      • #include
      • #define
      • #ifdef
      • #pragma
      • Predefined Macros
    • LValue and RValue
    • 🪅Data Types
      • Enum
      • TypeDef
      • const in c++
      • extern vs inline
    • 🎭Casting
    • 🔃Operator overloading
      • Available Operators
      • Examples of operator overloading
    • 🗺️Namespace
      • Namespace Example
      • Using directive
    • 🕵️Header File
      • For C++ Classes
    • 🏗️Structure
      • Struct vs Class
      • Public vs Private inheritance
    • 🏢Classes
      • Friend Function
      • Copy Constructor
      • Explicit Constructor
      • Move Constructor
        • Move Semantics
      • Other constructors
      • Virtual functions
      • Pure virtual function
      • Other function declaration
      • const function vs final function
  • Memory
    • 🧠Memory Introduction
    • ✨Heap and Stack
    • 🎯Pointers
      • Dangling Pointer
      • 'this' Pointer
      • Function Pointer
      • Smart Pointers
        • Unique Pointer
        • Shared Pointer
        • Weak Pointer
      • Reference count
    • 👨‍🏭Helper function
    • 🍡Vector [ArrayList]
      • Custom vector, part 1
      • Custom vector, part 2
      • Custom vector, part 3
      • std::vector
    • ♻️Union
      • Type Punning
      • Type Punning, part 2
      • Type Punning, part 3
      • Union, part 1
      • Union, Part 2
  • Thread
    • 🧵Threading
      • std::thread
      • Detach a thread
  • Misc
    • 🗂️Execution Order
    • 🧠Print memory
Powered by GitBook
On this page
  1. Code
  2. Operator overloading

Available Operators

Not all operators are available for overloading, Here is a list of available operators for overloading.

Arithmetic Operators:

  • + (addition)

  • - (subtraction)

  • * (multiplication)

  • / (division)

  • % (modulus)

Assignment Operators:

  • = (assignment)

  • += (addition assignment)

  • -= (subtraction assignment)

  • *= (multiplication assignment)

  • /= (division assignment)

  • %= (modulus assignment)

Comparison Operators:

  • < (less than)

  • > (greater than)

  • <= (less than or equal to)

  • >= (greater than or equal to)

  • == (equal to)

  • != (not equal to)

Increment/Decrement Operators:

  • ++ (increment)

  • -- (decrement)

Logical Operators:

  • && (logical AND)

  • || (logical OR)

  • ! (logical NOT)

Bitwise Operators:

  • & (bitwise AND)

  • | (bitwise OR)

  • ^ (bitwise XOR)

  • ~ (bitwise NOT)

  • << (left shift)

  • >> (right shift)

Member Access Operators:

  • . (dot operator)

  • -> (arrow operator)

Subscript Operator:

  • [] (subscript operator)

Function Call Operator:

  • () (function call operator)

Comma Operator:

  • , (comma operator)

New and Delete Operators:

  • new (memory allocation)

  • delete (memory deallocation)

Important Notes

  • You cannot overload operators for built-in types like int, float, etc.

  • Overloaded operators must have at least one operand of user-defined type.

  • The return type of an overloaded operator function is usually the same as the left-hand operand's type.

  • Overloading can be done for both member functions and global functions.

By understanding these overloadable operators and their guidelines, you can effectively extend the behavior of your custom classes in C++.

PreviousOperator overloadingNextExamples of operator overloading

Last updated 8 months ago

🔃