📅 2010-Nov-24 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ cpp, functors, pointers ⬩ 📚 Archive
Functor
In C++, a functor is an object whose class has the operator ()
function. If we have an object foo of a functor class Foo, we can call the operator() function by simply foo().
class Foo
{public:
void operator() ()
{"What a fine day!" << endl;
cout <<
}
};
int main()
{
Foo foo;
foo();return 0;
}
Pointer to Functor
If we have a pointer to a functor, here are a few ways of calling the function through that pointer:
new Foo();
Foo* foo =
// Using indirection operator to dereference the pointer
(*foo)();
// Using the member access operator
operator()(); foo->