Functor (function object) in C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Functor (function object) in C++

Hello, can someone please explain what the definition of a functor in c++ is and how it is used?

23rd Feb 2020, 9:51 PM
Гергана Иванова
Гергана Иванова - avatar
4 Answers
+ 5
A function is a block of code which only runs when it is called. You can pass data, known as parameters, into a function. Functions are used to perform certain actions, and they are important for reusing code: Define the code once, and use it many times
24th Feb 2020, 8:59 PM
gabi rete
gabi rete - avatar
0
gabi rete They were asking what a functor is. You explained what a function is. For an explanation on what a functor is, please see: https://www.geeksforgeeks.org/functors-in-cpp/amp/
24th Feb 2020, 10:16 PM
The Boxed Person
The Boxed Person - avatar
0
Thank you for the replies! The geeksforgeeks article is something I have read but it still does not provide the needed help. What I am trying to do is apply an STL algorythm with objects and for that a functor would be of great help if only I could get the gist of it...
12th Mar 2020, 4:04 PM
Гергана Иванова
Гергана Иванова - avatar
0
In basic terms a functor is an object whose class has the application operator ( () ) overloaded. It is an object that is basically used to pass a function to as an argument to another function.
15th Jun 2020, 6:56 PM
Anthony Maina
Anthony Maina - avatar