#include <functional> using namespace std::placeholders; class Class { public: Class(const std::string& name) : m_name(name) {} int member(int intArg, float floatArg) { std::cout << "I am a non-static member of " << m_name << ": " << intArg << ", " << floatArg << "." << std::endl; return 0; } private: std::string m_name; }; static int nonMember(Class* who, int intArg, float floatArg) { std::cout << "I am a static wrapper." << std::endl; return who->member(intArg, floatArg); } static int doSomething(std::function<int(int, float)> f, int intArg, float floatArg) { return f(intArg, floatArg); } int main(int argc, char** argv) { Class c("misiu"); Class d("czuterek"); return doSomething(std::bind(nonMember, &c, _1, _2), 1, 2.3f) + doSomething(std::bind(nonMember, &d, _1, _2), 4, 5.6f); }
produces the following output:
I am a static wrapper. I am a non-static member of misiu: 1, 2.3. I am a static wrapper. I am a non-static member of czuterek: 4, 5.6.