【发布时间】:2021-04-19 09:36:39
【问题描述】:
我在第 3 部分中阅读了有关 std::function 的这个(长)答案,关于 C++ 中的回调 https://stackoverflow.com/a/28689902/3832877,它演示了使用在括号中具有其他类型的模板参数。我的意思的例子:
std::function<int(int, float)> foo; //for a function returning int with one int and one float argument
std::function<int(C const &, int)> moo; //from the above thread, for member function of class C taking one int argument and returning int
我了解std::function 中定义函数签名的用法,但我不明白编译器如何解析这些模板参数。括号中的类型对编译器意味着什么?此语法是否还有其他用途,还是专门为std::function 和相关的 STL 类创建的?我可以编写自己的使用这种语法的类吗?
【问题讨论】:
标签: c++ templates c++17 std-function