Answers for "functors in c++"

C++
0

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
Posted by: Guest on February-19-2021

Browse Popular Code Answers by Language