如何使用std :: function指向功能模板 [英] how to use std::function to point to a function template
本文介绍了如何使用std :: function指向功能模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <functional>
int func(int x, int y)
{
return x+y;
}
int main()
{
typedef std::function<int(int, int)> Funcp;
Funcp funcp = func;
return 0;
}
但是可以指向模板函数吗?
But is it possible to point to a template function?
#include <functional>
template<class T>
T func(T x, T y)
{
return x+y;
}
int main()
{
typedef std::function<?(?, ?)> Funcp;
Funcp funcp = func;
return 0;
}
推荐答案
否.模板功能就是模板.这不是一个真正的功能.您可以将std :: function指向模板函数的特定实例,例如func<int,int>
No. A template function is exactly that, a template. It's not a real function. You can point a std::function to a specific instantiation of the template function, e.g. func<int,int>
这篇关于如何使用std :: function指向功能模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文