functor c++ code example
Example: functors in c++
class Solution
{
public :
int operator()(int n) // overloading the operator ()
{
return n*n;
}
};
int main()
{
Solution solve; // making an function object
cout<<solve(3)<<"\n"; // passing three as a parameter in the function object
}
// output -> 9