模板函数根据类型返回类的静态函数。但是如何使用对象作为推导类型的参数呢?
class A {
public:
static funcA() {}
static funcB() {}
static funcC() {}
...
};
class B {
public:
static funcA() {}
static funcB() {}
static funcC() {}
...
};
using funcType = std::function<void()>
template<typename T>
funcType getfunByType(T t) {
return T::funcA
}
int main() {
A a;
B b;
// void* p = nullptr; ??
bool s = false;
if (s) {
p = &a;
} else {
p = &b;
}
// funcType func = getfunByType(&p); ???
return 0;
}