In C++ I can chose between function pointers and function references (or even function values for the sake of completeness):
void call_function_pointer (void (*function)()) {
(*function) ();
}
void call_function_reference (void (&function)()) {
function ();
}
void call_function_value (void function()) {
function ();
}
When it comes to methods however, I don't seem to have this choice between pointers and references.
template <class T> void call_method_pointer (T* object, void (T::*method)()) {
(object->*method) ();
}
// the following code creates a compile error
template <class T> void call_method_reference (T& object, void (T::&method)()) {
object.method ();
}
This leads me to the assumption that method references do not exist in C++. Is that true? If it is, what is the reason they do not exist?