zoukankan      html  css  js  c++  java
  • std::get<C++11多线程库>(07):向线程函数传递参数(4)

    1  /*
    2  * 问-思考:
    3  * 1. std::thread 构造函数的第一个参数为重载函数时, 如何决定哪一个重载函数才是我们想要调用的?
    4  */
     1 //! [0] ====================== * 问-思考-1 *==================
     2 //!     std::thread 构造函数的第一个参数为重载函数时, 如何决定哪一个重载函数才是我们想要调用的?
     3 void func(int a){
     4     std::cout<<"a: "<<a<<std::endl;
     5 }
     6 void func(int a, int b, int c){
     7     std::cout<<"a: "<<a<<"  b:"<<b<<"  c:"<<c<<std::endl;
     8 }
     9 
    10 int main(int argc, char *argv[])
    11 {
    12     QCoreApplication a(argc, argv);
    13 
    14     //错误写法:
    15     //std::thread _t1(func, 1);       //error info: C2661: std::thread:没有重载函数接受2个参数
    16     //std::thread _t2(func, 1, 2, 3); //error info: C2661: std::thread:没有重载函数接受4个参数
    17 
    18     //正确写法:
    19     std::thread _t1((void (*)(int))func, 1);
    20     std::thread _t2((void (*)(int, int, int))func, 1, 2, 3);
    21 
    22     _t1.join();
    23     _t2.join();
    24     return a.exec();
    25 }
    26 //! [0]

    std::get<C++11多线程库>(07):向线程函数传递参数(5)

    原创文章, 转载请注明出处!

  • 相关阅读:
    Bubble Sort (5775)
    Dertouzos (5750)
    codeforces 360 E
    codeforces 360 D
    codeforces 360 C
    Mike and Cellphone
    训练2——B
    训练1——A
    符号三角形
    Sudoku Killer
  • 原文地址:https://www.cnblogs.com/azbane/p/15335084.html
Copyright © 2011-2022 走看看