//lamda
//first lamda
[]
{};

// second lamda
[]() //or no need () when paramater is null
{
std::cout << "second" << std::endl;
}();// last add(), express will call this lamda func

// 3 with return type
auto kkk = []()
{
return 1;
}();

// 4, set return type
auto kkkk = [] (int i) -> bool { return (bool)i; }(5);

//5, lamda capture, [=], [=,&], [&], [this][] 不捕获...
/*[&] 以引用的方式捕获
[=] 通过变量的一个拷贝捕获
[=, &foo] 通过变量的拷贝捕获,但是用foo变量的引用捕获
[bar] 通过复制捕获,不要复制其他
[this] 捕获this指针对应成员
*/

function, bind等,上代码

#include <iostream>
#include <functional>
using namespace std;
typedef std::function<void()> fp;
typedef std::function<void(int)> fpi1;
void g_fun()
{
std::cout << "global function bind" << std::endl;
} class A
{
public:
static void aFunStatic()
{
std::cout << "aFunStatic" << std::endl;
} virtual void aFun()
{
std::cout << "aFun" << std::endl;
} void aFunI1(int i)
{
std::cout << "aFunI1:" << i << std::endl;
} }; class DerivedA
:public A
{
public:
virtual void aFun() override
{
std::cout << "aFun in DeriveA" << std::endl;
}
}; class B
{
public:
void bCallAFun()
{
if(callFun)
callFun();
}
void bCallAFunStatic()
{
if(callFunStatic)
callFunStatic();
} void bCallAFunI1(int i)
{
if(callFunI1)
callFunI1(i);
} fp callFunStatic;
fp callFun;
fpi1 callFunI1;
}; void main()
{
B b;
A a; //bind to global function
fp f = fp(&g_fun);
f(); //bind to class function
//static
b.callFunStatic = std::bind(&A::aFunStatic);
b.bCallAFunStatic(); //no static function without parameter
b.callFun = std::bind(&A::aFun, &a);
b.bCallAFun(); //no static function with parameter
b.callFunI1 = std::bind(&A::aFunI1, &a, std::placeholders::_1);
b.bCallAFunI1(); //about polymorphic
DerivedA da;
b.callFun = std::bind(&A::aFun, &da);
b.bCallAFun();
}

最新文章

  1. JS实战 &#183; 仿css样式选择器
  2. Delphi 调用Dll的两种方式
  3. Python成长笔记 - 基础篇 (七)python面向对象
  4. 如何对于几百行SQL语句进行优化?
  5. python super
  6. android之location01
  7. jboss5优化
  8. Struts2的零配置和rest插件
  9. MDAC 在WINDOWS XP SP3 不能安装 的解决方法
  10. mysql事务回滚
  11. mongodb Install the MongoDB service
  12. 【剑指offer】面试题41:和为 s 的两个数字 VS 和为 s 的连续正数序列
  13. C# selecd,new,virtual,abstract与override
  14. Reactor三种线程模型与Netty线程模型
  15. python—异常
  16. word2vec生成词向量和字向量
  17. SpringBoot集成Jasypt安全框架,配置文件内容加密
  18. apache2.4多站点配置
  19. input标签(文本域和文件域)
  20. UVA-816.Abbott&#39;s Tevenge (BFS + 打印路径)

热门文章

  1. Docker for windows 7 - 加载 docker images
  2. python学习(二十二) String(上)
  3. oracle autotrace使用
  4. IO模型之阻塞IO
  5. nginx+php产生大量TIME_WAIT连接解决办法
  6. cento7.3下玩转sphinx
  7. [转] FTP主动模式和被动模式的区别
  8. DataSnap 连接池 DSServer1Disconnect
  9. mybatis 传入集合参数遍历 查询总结
  10. Nginx 安装与使用