Pointer to method is a not very used technique (I think), and so few people know. I had to search a bit to find out that you need to use additional parentheses when using the pointer. Note that it is necessary to have an object to call the method through the pointer.
This applies to non-static methods. Pointers to static methods are not special, they are declared in the same way as pointers to "common" functions (which are not members of a class).
#include <iostream>
using namespace std;
class Menu
{
public:
int validaEscolha();
static int stValidaEscolha();
int inicial();
};
int Menu::validaEscolha()
{
cout << 1232 << endl;
return 1;
}
int Menu::stValidaEscolha()
{
cout << 1232 << endl;
return 1;
}
int Menu::inicial()
{
// ponteiro para método não estático
int (Menu::*funcs)() = &Menu::validaEscolha;
(this->*funcs)();
// ponteiro para método estático
int (*stFuncs)() = &Menu::stValidaEscolha;
stFuncs();
return 0;
}
int main()
{
Menu m;
m.inicial();
}