Hvis det virkeligt er det du vil, kan man kaste sig ud i nogen function pointere:
#include <iostream>
class MyClass
{
public:
MyClass(int i)
{
if(i == 1)
{
Func1 = &MyClass::Func11;
Func2 = &MyClass::Func12;
}
else
{
Func1 = &MyClass::Func21;
Func2 = &MyClass::Func22;
}
}
int (MyClass::*Func1)(int, int);
int (MyClass::*Func2)(int, int);
private:
int Func11(int, int)
{
std::cout << "Func11" << std::endl;
return 11;
}
int Func12(int, int)
{
std::cout << "Func12" << std::endl;
return 12;
}
int Func21(int, int)
{
std::cout << "Func21" << std::endl;
return 21;
}
int Func22(int, int)
{
std::cout << "Func22" << std::endl;
return 22;
}
};
int main()
{
MyClass C1(1);
MyClass C2(1);
(C1.*(C1.Func1))(1, 1);
(C2.*(C2.Func2))(2, 2);
}
Bemærk den lidt specielle syntax.