How to Overload the Function Call Operator () in C++? Last Updated : 07 Feb, 2024 Comments Improve Suggest changes Like Article Like Report 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 Operator Now, 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++ // Program to demonstrate how to overload () operator #include <iostream> using namespace std; class GFG { public: // Overloading the function call operator to check leap // year bool operator()(int year) const { return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)); } }; int main() { // Creating an instance of the GFG functor GFG isLeapYear; // Year to be checked int year = 2024; // Checking if the year is a leap year using the functor if (isLeapYear(year)) { cout << year << " is a leap year." << endl; } else { cout << year << " is not a leap year." << endl; } return 0; } OutputThe Sorted array: 15 15 25 27 38 67 95 Comment More infoAdvertise with us Next Article How to Overload the Function Call Operator () in C++? M mguru4c05q Follow Improve Article Tags : C++ Programs C++ cpp-operator cpp-operator-overloading CPP-OOPs CPP Examples +2 More Practice Tags : CPPcpp-operator Similar Reads Overloading of function-call operator in C++ In this article, we will discuss the Overloading of the function-call operators in C++. The function call operator is denoted by â()â which is used to call function and pass parameters. It is overloaded by the instance of the class known as a function object.When the function call operator is overlo 3 min read How to Overload the (+) Plus Operator in C++? In C++, operator overloading is a feature of the OOPs concept that allows you to redefine the behavior for different operators when they are used with objects of user-defined classes. The plus operator (+) is a binary operator generally used for addition. In this article, we will learn how to overlo 2 min read How to Overload the Multiplication Operator in C++? In C++, the multiplication operator is a binary operator that is used to find the product of two numeric values. In this article, we are going to learn how to overload the multiplication operator for a class in C++. Overloading Multiplication Operator in C++C++ provides the functionality of operator 2 min read How to Overload the Less-Than (<) Operator in C++? In C++ we have an operator called less than operator (<) which checks if the left side operand is smaller than the right side operand or not. In this article, we will learn how to overload the less-than operator in C++. Overloading Less-Than Operator in C++In C++, we can overload the less-than op 2 min read How to Create a Function Template in C++? In C++, templates enable us to write generic programs that handle any data type. We can create a template class, function, and variable. A template function is a function that can work with any data type. In this article, we will learn how to create a function template in C++. Create a Function Temp 2 min read Like