zoukankan      html  css  js  c++  java
  • C++回调函数示例

    模板 + Boost::Function。示例代码:

    #include <string>
    #include 
    <iostream>
    #include 
    <boost/function.hpp>

    using namespace std;
    using namespace boost;

    class Test
    {
    public:
        Test(){};
        
    virtual ~Test(){};
        
        
    void Handle(string& s, unsigned int lines)
        {
            
    for(int i=0; i< lines; i++)
            {
                cout 
    << s << endl;
            }
        };
    };

    template 
    <class T>
    static void CallBack(T& t, boost::function<void (T*string&, unsigned int)> f)
    {
        
    string s("test");
        f(
    &t, s, 3);
    };

    int main()
    {
        Test test;
        CallBack
    <Test>(test, &Test::Handle);
        
    return 0;
    }

    版权所有,欢迎转载
  • 相关阅读:
    mariadb 数据库集群配置
    mariadb 4
    mariadb 3
    mariadb 2
    mariadb 1
    firewalld 防火墙
    k8s集群搭建
    k8s控制器资源
    k8s Ingress和ingress控制器
    k8s service对象
  • 原文地址:https://www.cnblogs.com/xiaotie/p/368221.html
Copyright © 2011-2022 走看看