🧾 UNIT III: Overloading and Inheritance


šŸ”¹ Operator Overloading in C++

šŸ”ø Theory:

Operator overloading allows us to redefine the way operators work for user-defined types (like classes). In C++, this is done using special functions called operator functions. This enhances code readability and usability, enabling operations such as +, -, or == to work naturally with objects.

Syntax of operator overloading:

return_type class_name::operator op(argument_list) {
    // body
}

You can overload:

āš ļø Note: You cannot overload operators like ::, ., .*, sizeof, and ?:.


šŸ”¹ Overloading Unary Operators

šŸ”ø Theory:

Unary operators work on a single operand. Overloading them allows applying operations like negation, increment, or decrement on objects.

Unary operator overloading in C++ allows the redefinition of operators that act on a single operand when applied to objects of user-defined types (classes).Ā This enables customization of behavior for operators likeĀ ++Ā (increment),Ā --Ā (decrement),Ā -Ā (unary minus/negation), andĀ !Ā (logical NOT).