zoukankan      html  css  js  c++  java
  • C++基础-结构体成员函数与多线程th1(&func::run, fun1, "xxx")

    结构体成员函数的引用

    1.空类指针可以引用没有调用内部变量的成员函数

    2.可以调用类成员函数变量来进行thread操作

    //
    // Created by Administrator on 2021/6/27.
    //
    #include<iostream>
    #include<thread>
    #include <windows.h>
    
    using namespace std;
    
    struct func{
        int i;
        void run()
        {
            //i = 3;
            MessageBoxA(0, "12345", "ABCDE", 0);
            cout << "hello china, hello cpp" << std::endl;
        }
        void run1(const char* str)
        {
            //i = 3;
            MessageBoxA(0, str, str, 0);
            cout << "hello china, hello cpp" << std::endl;
        }
    };
    
    int main()
    {
        //func *p(nullptr);
        //p->run(); //空类指针可以引用没有调用内部变量的成员函数
    
        func fun1;
        //&fun::run引用成员函数
        thread th1(&func::run, fun1);
        thread th2(&func::run, fun1);
    
        thread th3(&func::run1, fun1, "fangfang");
        thread th4(&func::run1, fun1, "huahua"); //传递参数模式
    
        cin.get();
    
    }
  • 相关阅读:
    leetcode
    vue初尝试--组件
    vue初尝试--项目结构
    vue初尝试--新建项目
    SQL取xml中节点值
    UI设计
    Asp.NET中Gridview CSS---Office2003风格
    Jquery+JSON+WebService使用总结
    ASP.NET 如何固定表格表头(fixed header)
    项目总结
  • 原文地址:https://www.cnblogs.com/my-love-is-python/p/14940462.html
Copyright © 2011-2022 走看看