跳至主要內容

How to Use std::function to Write a Callback Function in C++

(the post is automatically translated by AI) Introduction std::function is a C++11 feature defined in the <functional> header. It’s similar to a function pointer in C, but more general: any CopyConstructible Callable object can be stored, copied, and invoked through it. Examples of such objects include functions, lambda expressions, bind expressions, as well as pointers to member functions and member data. The stored callable object is referred to as the std::function’s target. If no target is assigned, the std::function is called empty, and invoking it will throw std::bad_function_call. ...

January 18, 2022 · 2 min · GanniPiece