Are function pointers functors ? Is there a virtual functor in use that helps sibling functors compile silently ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
At least as the term is normally used in C++ (Warning: it’s used entirely differently relative to other languages such as Haskell), a functor is a class (or an instance of a class) that overloads
operator()so it can be invoked like a function.Since they use the same syntax, a template can be written to accept either a pointer to a function or an instance of a functor interchangeably. Not all algorithms will do so however — some expect (for example) that you supply something with
typedefs for things likeargument_typeandresult_type. The standard library provides a couple of classes (unary_functionandbinary_function) to use as base classes for your functors to supply these. You can supply them on your own if you prefer — these base classes are purely for convenience (and some people don’t find them particularly convenient).