How to assign functor to function pointer?
问题 Generally, can I assign a function object to a function pointer? I want to do something like this: #include <iostream> class Foo { int num; public: Foo(int num_par) : num(num_par) {} void operator()(int multiplier) { std::cout << multiplier * num << std::endl; } }; int main() { typedef void(*bar)(int); Foo f(42); bar b = f; // MSVC error // ^ C2440: 'initializing' : cannot convert from 'Foo' to 'bar' b(2); // wanted to print 84 } If that's impossible, I’d like an alternative specifically for