![]() |
In C++, operator overloading allows the user to redefine the behavior of an operator for a class. Overloading the function call operator () allows you to treat objects like functions enabling them to be called as if they were functions. Such classes are called functors in C++. In this article, we will learn how to overload the () function call operator in C++. Overloading Function call Operator () in C++In C++, the function call operator () is overloaded by defining the member function named operator() inside a class. When an object of this class is used with the () operator, it will behave as a function executing the body of the member function operator(). C++ Program to Overload Function Call OperatorNow, let’s create a functor to check if a given year is a leap year. The functor will be callable to perform the check. C++
Output
The Sorted array: 15 15 25 27 38 67 95 |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 16 |