Hello,
I would like to use a functor which is also calling an other functor. I am not sure if I am using the right terminology. I manage to use only one functor but not a nested one. I have the following code:
#include <iostream>
usingnamespace std;
template<typename T>
class Prueba {
public:
template<typename Function, typename Normalization >
staticvoid usesnormalize (Function lafuncion, Normalization normalize, T a) {
lafuncion (normalize, a);
}
template<typename Normalization>
staticvoid lafuncion1 (Normalization normalize, T a) {
normalize (a);
}
staticvoid normalize1 (T a) {
cout << "normalize1. " << endl;
}
staticvoid normalize2 (T a) {
cout << "normalize2. " << endl;
}
};
int main (int argc, char* argv[] ) {
int b;
Prueba<int>::usesnormalize (Prueba<int>::lafuncion1, Prueba<int>::normalize2, b );
int a;
Prueba<int>::lafuncion1 (Prueba<int>::normalize1, a );
}
I am getting the following error:
functiontemplate.cpp: In function ‘int main(int, char**)’:
functiontemplate.cpp:31: error: no matching function for call to ‘Prueba<int>::usesnormalize(<unresolved overloaded function type>, void (&)(int), int&)’
You need to specify the template parameter Prueba<int>::usesnormalize (Prueba<int>::lafuncion1<void (*)(int)>, Prueba<int>::normalize2, b );
Horrible, don't you think?
My code can also be written by using global functions instead of static member functions. I think I meant by functor a function object, as it is explained in:
In addition to class type functors, other kinds of function objects are also possible in C++. They can take advantage of C++'s member-pointer or template facilities. The expressiveness of templates allows some functional programming techniques to be used, such as defining function objects in terms of other function objects (like function composition). Much of the C++ Standard Template Library (STL) makes heavy use of template-based function objects.
Apparently, functors are a kind of function objects.