Home >Backend Development >C++ >How to Correctly Store Member Function Pointers in a `std::function` Map?
Storing Member Function Pointers in std::function Map for a Single Class
When attempting to store function pointers to member functions of a specific class in a std::function map, it's crucial to understand the requirement for a non-static member function to be called with an object.
In the provided code, the error stems from the incorrect function signature of std::function
The corrected code snippet would be:
To further bind a function with parameters, C placeholders or C 11 lambdas can be utilized. Here are examples for these approaches:
Using Placeholders:
Using Lambdas (C 11):
The above is the detailed content of How to Correctly Store Member Function Pointers in a `std::function` Map?. For more information, please follow other related articles on the PHP Chinese website!