If you want to pass a function parameter which method is better to use: functor or functor2?Code:#include <string> #include <iostream> using namespace std; struct Functor{ bool operator()(const std::string& str){cout<<str<<endl;return true;} }; struct Functor2{ static bool compute(const std::string& str){cout<<str<<endl;return true;} }; struct Foo { template<class F> void callMe() { F()("operator ()"); } template<class F> void callMe2() { F::compute("static"); } }; int main(int n,char ** arfv) { Foo obj; obj.callMe<Functor>(); obj.callMe2<Functor2>(); system("pause"); }
Bookmarks