How to create a function object in C++?

To create a function object we have to create a class that overloads the operator() function.

Syntax to create a function object:

template <class Arg, class Result> struct unary_func {

typedef Arg arg_type;

typedef Result result_type;


template <class Arg1, class Arg2, class Result>

struct binary_func {

typedef Arg1 first_arg_type;

typedef Arg2 second_arg_type;

typedef Result result_type;


Leave a Reply