我希望能够形成一个只知道类本身和方法名称的成员指针类型。不幸的是,我无法在我的类中使用 const 和非常量方法变体。
示例代码片段:
struct A
{
void method() {}
void method() const {}
};
int main()
{
decltype(&A::method) _;
}
Run Code Online (Sandbox Code Playgroud)
我也尝试了以下方法,但也没有取得多大成功:
decltype(&(std::declval<const A>().method)) _;
Run Code Online (Sandbox Code Playgroud)
decltype由于歧义,这两种方法都失败了,因为无法解决这个问题:
'decltype cannot resolve address of overloaded function'
我怎样才能以其他方式实现这一目标?