Function call operator
suggest changeYou can overload the function call operator ():
operator() must be a member function of a class, struct, or union. A non-member operator() is ill-formed:
//R -> Return type
//Types -> any different type
R operator()(Type name, Type2 name2, ...)
{
//Do something
//return something
}
// Use it like this (R is the return type; a and b are variables).
R foo = object(a, b, ...);
For example:
struct Sum
{
int operator()(int a, int b)
{
return a + b;
}
};
//Create instance of struct
Sum sum;
int result = sum(1, 1); //result == 2
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents