1. 程式人生 > 其它 >C++基礎-結構體成員函式與多執行緒th1(&func::run, fun1, "xxx")

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