C++ - Chapter 4: Function
Functions Functions are self-contained blocks of code designed to perform specific tasks. They promote code reusability, modularity, and abstraction. Functions can participate in polymorphism through: Compile-time polymorphism (Static Polymorphism) Function overloading Operator overloading Function templates Runtime polymorphism Virtual functions 1. Function Overloading Function overloading allows creating multiple functions with the same name but different parameter types or parameter counts. Different return types alone are not enough to overload a function. Function delete using delete keyword. Default-arguments is a default value provided for a function parameter. Parameters with default arguments must always be the rightmost parameters, and they are not used to differentiate functions when resolving overloaded functions. void print_int(int x) {} void print_int_or_default(int x, int y = 2) {} template <typename T> void print_int(T) = delete; void main() { print_int(97); // okay // printInt('a'); // compile error // printInt(true); // compile error print_int_or_default(5); // prints: 5, 2 print_int_or_default(5, 10); // prints: 5, 10 } 2. Operator Overloading Operator overloading allows C++ operators to be customized for user-defined types. ...