模板 – C std ::函数式模板语法
发布时间:2020-12-16 03:08:14 所属栏目:百科 来源:网络整理
导读:在C 11中,您可以像这样实例化std ::函数: std::functionvoid(int) f1;std::functionint(std::string,std::string) f2;//and so on 但是,尽管有很多关于网络上的可变模板的信息,但我没有找到任何关于如何编写std :: function-like模板的文章,该模板将接受括
在C 11中,您可以像这样实例化std ::函数:
std::function<void(int)> f1; std::function<int(std::string,std::string)> f2; //and so on 但是,尽管有很多关于网络上的可变模板的信息,但我没有找到任何关于如何编写std :: function-like模板的文章,该模板将接受括号括号. 解决方法
没有什么特别的,它是一个普通的功能类型.当你声明这样的功能:
int foo(char a,double b) 那么它的类型是int(char,double).单个参数类型和返回类型的“解包”的一种方法是使用部分模板专门化.基本上,std :: function看起来像这样: template <class T> struct function; // not defined template <class R,class... A> struct function<R (A...)> { // definition here }; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |