educative.io

Educative

Function objects or functors

function objects or, wrongly, as functors

, but some Words and Lines later you use functors again. That is confusing, what is the right designation?


Type your question above this line.

Course: https://www.educative.io/collection/10370001/5128982204776448
Lesson: https://www.educative.io/collection/page/10370001/5128982204776448/6582573192970240

Please note that Functors are different than simple functions. In functional programming, a functor is a design pattern inspired by definition from category theory that allows for a generic type to apply a function inside without changing the structure of the generic type.
For example there is an important function which accepts only one argument. But in order to call that function there is a lot of information we wanted to pass to that function, but function is accepting only one argument. One obvious answer to this question is to use the global variables but good coding practices do not advocate the use of global variables.
In this case we will use Functors which are objects that can be treated as though they are function or pointer to functions.

#include <iostream>
class myFunctorClass
{
public :
myFunctorClass ( int x) : _x( x ) {}
int operator() ( int y) { return _x + y; }
private :
int _x;
};
int main()
{
myFunctorClass addFive( 5 );
std::cout << addFive( 6 );
return 0;
}

Thanks but sorry, that is not an answer to my question. What I asked for was NOT , what is a Functor! I asked what designation or lets say name is the right one for a function object, because in the lessen is written,

function objects or, wrongly, as functors

but afterwards “functors” is used as designation. Confusing is to say that is not right but than do it not right.

Actually I explained about the Functor, because functor are little different than functions, so whenever you see a functor then this must be in your mind.

Thank you, that is well meant, but is not the subject of my question. I wonder if I have expressed myself badly, because English is not my native language and I’m not sure yet if it is clear now.
That funtions and functors are different is quite clear, but is functors the right term is the question, or why is functors used as a term when shortly before it was said, that is not the right term.
This question can actually only be answered by those who wrote the original text, which I have partially quoted.