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 How to Create a Pointer to a Function in C++? In C++, a function pointer is a variable that stores the address of a function that can later be called through that function pointer. It is useful for passing functions as parameters to other functions(callback functions) or storing them in data structures. In this article, we will learn how to use 2 min read How to call function within function in C or C++ When we begin programming in C/C++, we generally write one main() function and write all our logic inside this. This approach is fine for very small programs, but as the program size grows, this become unmanageable. So we use functions. We write code in the form of functions. The main function alway 4 min read How to Create a Pure Virtual Function in C++? In C++, pure virtual functions are those functions that are not implemented in the base class. They are instead implemented in the derived classes if necessary. In this article, we will discuss how to create a pure virtual function in a class in C++. How to Create a Pure Virtual Function in C++? To 2 min read How to Use Default Arguments in Function Overloading in C++? In C++, we can provide the default values for the input arguments into the functions and it is also supported in function overloading. In this article, we will learn how to use default arguments in function overloading in C++. Default Arguments in Function Overloading in C++We can define the default 2 min read Overloading function templates in C++ Template: A template is a tool that reduces the efforts in writing the same code as templates can be used at those places.A template function can be overloaded either by a non-template function or using an ordinary function template. Function Overloading: In function overloading, the function may ha 3 min read Like