Just a quick question :
Are any classes or struct which has overloaded "operator()" function,its' object is called functors,right????
Please let me know this,thank u
I know that operator() is a function. My question was whether or not an object of a class or a struct which has overloaded this "operator()" function is called functors. I browsed the web for pretty reasonable amt of time just to make sure I know what exactly a functor is.
My question was whether or not an object of a class or a struct which has overloaded this "operator()" function is called functors.
According to Stroustrup perhaps not exactly:
The C++ Programming Language, Chapter 3.4.3 Function Objects:
One particularly useful kind of template is the function object (sometimes called a functor), which
is used to define objects that can be called like functions. For example:
1 2 3 4 5 6 7
template<typename T>
class Less_than {
const T val; // value to compare against
public:
Less_than(const T& v) :val(v) { }
booloperator()(const T& x) const { return x<val; } // call operator
};
The function called operator() implements the ‘‘function call,’’ ‘‘call,’’ or ‘‘application’’ operator ().
Apparently he seems to endorse the usage of ‘functor’ when it refers to template classes.
But I’ve actually come across a lot of examples of ‘functor’ as ‘simple’ (in the meaning: not template) classes which overload operator(), so I think the term is generally accepted in that meaning, i.e. a class(or struct) which overloads the operator(), regardless it is a template or not.
Example: https://stackoverflow.com/questions/356950/c-functors-and-their-uses