raghu said:
I got a document which says functors is a function with a
state and it can be implemented in C++. Can't we implement functors
in C language.
You can provide state in a C program by the use of static variables.
Whether this is a functor or not is a separate issue. What does the document
at issue define as a functor?
I think the number of static variables, that is the "complexity" of state,
is a good indicator of when a C++ class should be used instead of C coding
techniques. I doubt I would ever write a C function that had more than one
static variable; I would write a C++ class.
With my background I think of a functor as being basically a C++ member
function with the signature foo( <argument-list>).
I think the question posed leads you into the pointless and familiar
labyrinth of "can we write object oriented programs in C?", A place where I
think a lot of time has been wasted; you will always come back to
*definitions*. What in hell are the definitions of the terms being used in
the discussion? Answer: they are vague and/or different for the different
people involved in the discussion. IOW, all semantics and very little
useful substance.