Qt 5.14.1 (MSVC 2017,32Bit)
#include <iostream>
class MyClass {
public:
typedef void (MyClass ::*func) () ;
void func1() { std::cout << __FUNCTION__ << std::endl; }
void func2() { std::cout << __FUNCTION__ << std::endl; }
void func3() { std::cout << __FUNCTION__ << std::endl; }
func funcs[3] = {&MyClass::func1, &MyClass::func2, &MyClass::func3 };
QMap<int , func> m;
MyClass ()
{
m[0] = &MyClass::func1;
m[2] = &MyClass::func2;
m[4] = &MyClass::func3;
for(size_t i=0; i < sizeof(funcs)/sizeof(funcs[0]); i++)
{
(this->*funcs[i])() ;
}
if(m.contains(2)){
(this->*m[2])() ;
}
std::cout << __FUNCTION__ << std::endl;
}
};
int main(int argc, char **args ) {
QCoreApplication a(argc , args ) ;
MyClass obj;
for(size_t i=0; i< sizeof(obj.funcs)/ sizeof(obj.func[0]); i++)
{
(obj.*obj.funcs[i])();
}
(obj.*obj.funcs[0])();
(obj.*obj.funcs[1])();
(obj.*obj.funcs[2])();
return a.exec();
}