• C++基础-多线程扩展继承(public:thread)


    对thread进行继承,这里overite thread的构造方法 

     Huathread():thread(){ //子类调用父类的方法
    
        };
        template<typename T, typename...Args> //子类调用父类的构造函数, 可变参数的构造
        Huathread(T && func, Args &&...args):thread(std::forward<T>(func),forward<Args>(args)...)
        {
    
        }

    定义我们自己的方法

      void run(const char* cmd) //新增功能
        {
            system(cmd);
        }

    完整代码

    //
    // Created by Administrator on 2021/6/27.
    //
    #include<thread>
    #include<iostream>
    
    using namespace std;
    
    class Huathread : public thread{
    public:
        Huathread():thread(){ //子类调用父类的方法
    
        };
        template<typename T, typename...Args> //子类调用父类的构造函数, 可变参数的构造
        Huathread(T && func, Args &&...args):thread(std::forward<T>(func),forward<Args>(args)...)
        {
    
        }
    
        void run(const char* cmd) //新增功能
        {
            system(cmd);
        }
    
    };
    int main()
    {
        Huathread t1([](){
            cout << "hello this is huahua" << endl;
        });
        t1.run("calc");
    
        Huathread t2([](int num){
            cout << "hello this is huahua" << num << endl;
        }, 100);
        t1.run("notepad");
        cin.get();
    }
  • 相关阅读:
    记事本:js简介
    python 类的魔法函数 内置函数 类方法 静态方法 抽象类
    python 类
    python 列表 元组 字典 集合
    python:函数和循环判断
    记事本:盒模型
    第5章学习小结
    倍增法求LCA(最近公共最先)
    L
    第4章学习小结
  • 原文地址:https://www.cnblogs.com/my-love-is-python/p/14940799.html
Copyright © 2020-2023  润新知