【发布时间】:2019-03-01 11:49:39
【问题描述】:
我尝试将成员函数 (func) 的引用提供给函数 (Multiprotocol),并使用此类的对象 (z) 调用它。 但我的线路有问题
result = z.*f(std::forward<Args>(args)...));
我尝试过类似的东西
z.(*f) (std::forward<Args>(args)...))
和
z.(*(&f)(std::forward<Args>(args)...));
但我不知道该怎么做。有人可以帮帮我吗?
class test
{
public:
static int func()
{
std::cout << "in func";
}
};
class MultiProtocol
{
public:
template<typename Function, typename... Args>
bool functionImpl(Function f, Args&&... args)
{
int result = 0;
result = z.*f(std::forward<Args>(args)...));
return result;
}
private:
test z;
};
主要是:
int main()
{
MultiProtocol rr;
rr.functionImpl(&test::func);
}
【问题讨论】:
标签: c++