【发布时间】:2020-12-31 15:55:06
【问题描述】:
我想做这样的事情:
struct S
{
void mf() {};
template <auto f>
void func()
{
f();
}
};
int main()
{
S x;
x.func<x.mf>();
}
但是,这些是错误:
error: no matching function for call to 'S::func<x.S::mf>()'`
note: candidate: 'template<auto f> void S::func()'
note: template argument deduction/substitution failed:
error: could not convert 'x.S::mf' from '<unresolved overloaded function type>' to 'void (S::*)()'
我不确定我是否理解我做错了什么。
既然我已经实例化了x,为什么x.mf 没有解析?我该如何进行这项工作?
【问题讨论】:
-
一个问题是您需要将一个指针传递给函数。
标签: c++ class templates c++17 member-function-pointers