获取特定的模板重载方法指针

Get a specific template overloaded method pointer

本文关键字:重载 方法 指针 获取      更新时间:2023-10-16

我有这个类:

class A{
    template<typename Type = int32_t> Type b(){}
    template<typename Type = int32_t> Type b(Type a, Type b){}
}

我想得到一个函数b<int>()b<int>(int, int)的指针

我试过这个,但它不知道该选择哪一个:

auto t = (void (A::*)(int,int))(&A::template b<int>);

你只需要:

auto t = static_cast<int(A::*)(int, int)>(&A::b<int>);

你的代码在你修复了一堆其他错误后工作。