小编Jav*_*uez的帖子

是否有可能获得函数模板的隐式实例化的地址?

我想知道是否有任何方法可以获取由一组特定参数生成的函数模板的实例化地址.

#include <iostream>

template <typename T>
class A {}; 

template <typename T, typename T2>
int hello(A<T> a, A<T2> b, int c)
{
    return 69; 
}

int main()
{
    A<int> a;
    A<float> b;
    std::cout << (&hello)(a, b, 3) << "\n";                                                                                                                                                           

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

此代码打印函数调用返回的值.如何打印为a和b参数实例化的"hello"版本的地址?我希望编译器能够推断出这些类型.

c++ templates c++11

11
推荐指数
1
解决办法
914
查看次数

标签 统计

c++ ×1

c++11 ×1

templates ×1