首页 > 其他 > 详细

std::function赋值的几种方法

时间:2014-06-09 17:41:43      阅读:2134      评论:0      收藏:0      [点我收藏+]

定义:

#include <functional>

std::function<void(const QString&)> myPrintFunction;

 

函数指针

void directPrint(const QString &msg)
{
    qDebug()<<"direct print:"<<msg;
}

myPrintFunction = directPrint;

 

lambda

myPrintFunction = [](const QString &s)
{
    qDebug()<<"lambda print:"<<s;
};

std::bind

Screen* screen = new Screen();
PrintFunction= std::bind(&Screen::print, screen, std::placeholders::_1);

std::function赋值的几种方法,布布扣,bubuko.com

std::function赋值的几种方法

原文:http://www.cnblogs.com/danju/p/3777439.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!