定义:

#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);

相关文章:

  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2021-05-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-24
  • 2021-11-06
相关资源
相似解决方案