Why do we use std::function in C++ rather than the original C function pointer? [duplicate]
问题 This question already has answers here : Should I use std::function or a function pointer in C++? (5 answers) Closed 2 years ago . What is the advantage of std::function<T1(T2)> over the original T1 (*)(T2) ? 回答1: std::function can hold more than function pointers, namely functors . #include <functional> void foo(double){} struct foo_functor{ void operator()(float) const{} }; int main(){ std::function<void(int)> f1(foo), f2((foo_functor())); f1(5); f2(6); } Live example on Ideone. As the