假设&
没有重载。如何获取实例化模板函数的地址,如std::sort<int*>
?以下不会在某些编译器上编译:
#include <algorithm>
int main()
{
&std::sort<int*>;
}
在 MSVC v19.21 上,它报告:https://godbolt.org/z/gpZCdn
error C2568: 'identifier': unable to resolve function overload
最佳答案
你可以使用
&std::sort<int*>;
&std::sort<int>
不起作用,因为类型需要可取消引用。
可以通过执行显式转换来解决歧义。
static_cast<void (*)(int*, int*)>(&std::sort<int*>);
关于c++ - C++ 03中如何引用实例化模板函数的地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57087276/