结构体成员函数的引用

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

}

 

posted on 2021-06-27 13:45  python我的最爱  阅读(152)  评论(0编辑  收藏  举报