您当前的位置: 首页 >  c++
  • 0浏览

    0关注

    1477博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C++ std::function怎么用

软件工程小施同学 发布时间:2021-08-31 15:28:25 ,浏览量:0

类模版std::function是一种通用、多态的函数封装。

std::function的实例可以对任何可以调用的目标实体进行存储、复制、和调用操作,这些目标实体包括普通函数、Lambda表达式、函数指针、以及其它函数对象等。

如下中的

typedef std::function Functional;

最外层的int为返回值类型,里层int为参数类型

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

typedef std::function Functional;

int TestFunc(int a)  
{  
    return a;  
}

int main()
{
    Functional obj = TestFunc;    
    int res = obj(1);
    std::cout             
关注
打赏
1665320866
查看更多评论
1.5875s