As I understood pointers to non-static methods, they’re no more useful than for providing an alias mechanism for a certain method. For example, having an object with three methods
class Provider
{
public:
int A(int in);
int B(int in);
int C(int in);
}
and a consumer that requires a pointer to a provider method (be it A, B or C). Having a controller that gives a pointer to one of the 3 methods to the so-called consumer, we can write something in the consumer code that uses a Provider instance and the pointer to either A, B or C, depending on what the controller sent.
If this is all that a pointer to a non-static method in C++ can do, is there still a way of providing a more “intelligent” pointer to an object’s method, without sending the object along with that method pointer to a consumer? In the affirmative case, what’s the idiom/mechanism called (even a way to simulate this qualifies as an answer I’m interested in).
Your concept of member functions pointers is correct in general.
Member functions pointers are actually very useful with conjunctions to such helpers, as
std::bind, orstd::function. Raw member function pointers are usually ugly.As for your example,
Your consumer can accept
std::function<return_type(args)>and you can pass binding of object and its member function to such consumer.such structs as
std::bindalso allows realization of such concepts as partial specialization and currying.