What is a functor (function object) and how does it differ from a regular function?

Last updated 21 June 2026

  • A functor is an object of a class overloading operator(), so it's callable like a function but can hold state in member variables (e.g. a threshold).

  • Each functor is a distinct type, so templates can inline its call. This often beats a function pointer.

  • Lambdas are sugar for compiler-generated functors (captures become members). Both are widely used as STL predicates and comparators (std::sort, std::count_if).

  • https://www.geeksforgeeks.org/cpp/when-to-use-a-functor-instead-of-a-function-in-cpp/
  • https://www.learncpp.com/cpp-tutorial/static-local-variables/
  • https://www.adaface.com/blog/cpp-interview-questions/
All C++ interview questions