继承自 std::函数、语法和用法

inherit from std::function, syntax and usage?

本文关键字:语法 用法 函数 std 继承      更新时间:2023-10-16

我不明白函子从 std::function 继承时的语法:

class do_sth : public function< any_type (another_type) >
{
    bool operator() (string s) {...}
};

我应该使用什么作为any_type和another_type?你能给我一个从 std::function 继承的有益用法的例子吗,因为我还没有理解它?

您应该将operator ()的返回类型用于any_type,将参数类型用于another_type。那么至少它适合。

但实际上,std::function并不意味着要继承,这样做可能是一个坏主意。