<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      C++并發(C++11)-03 向線程傳遞參數

      普通傳參

      #include <iostream>
      #include <string>
      #include <thread>
      using namespace std;
      
      void func(string m) {
        cout << "&m:" << &m;
        cout << endl;
      }
      
      int main() {
        string s = "xxxx";
        cout << "&s:" << &s << endl;
        thread t(func, s);
        t.join();
        return 0;
      }

       

       線程會將參數拷貝后訪問

      引用傳參:常量引用

      #include <iostream>
      #include <string>
      #include <thread>
      using namespace std;
      
      void func(const string& m) {
        cout << "&m:" << &m;
        cout << endl;
      }
      
      int main() {
        string s = "xxxx";
        cout << "&s:" << &s << endl;
        thread t(func, s);
        t.join();
        return 0;
      }

       

       線程會將參數拷貝后訪問

      引用傳參:非常量引用

      #include <iostream>
      #include <string>
      #include <thread>
      using namespace std;
      
      void func(string& m) {
        cout << "&m:" << &m;
        cout << endl;
      }
      
      int main() {
        string s = "xxxx";
        cout << "&s:" << &s << endl;
        thread t(func, ref(s));
        t.join();
        return 0;
      }

       

       此時要用到std::ref()將參數轉換成引用形式,線程訪問的變量與參數變量為同一地址。

      指針傳參

      #include <iostream>
      #include <string>
      #include <thread>
      using namespace std;
      
      void func(string* m) {
        cout << "m:" << m;
        cout << endl;
        *m = "yyy";
      }
      
      int main() {
        string* s = new string("xxx");
        cout << "s:" << s << endl;
        thread t(func, s);
        t.join();
        cout << "s:" << *s << endl;
        return 0;
      }

       

       此時,線程中的指針與參數指針指向同一地址。

      posted @ 2019-09-29 14:38  二杠一  Views(792)  Comments(0)    收藏  舉報
      主站蜘蛛池模板: 花式道具play高h文调教| 亚洲欧美偷国产日韩| 爱如潮水日本免费观看视频| 麻豆精品一区二区综合av| 韩国19禁无遮挡啪啪无码网站| 亚洲最大成人免费av| 国产精品线在线精品国语| 久热色精品在线观看视频| 国产av熟女一区二区三区| 波多野结衣一区二区三区高清| 久久精品无码一区二区三区 | 在线播放国产精品亚洲| 国产精品成人网址在线观看| 亚洲色大成网站www永久男同| 浙江省| 少妇人妻互换不带套| AV极品无码专区亚洲AV| 自拍偷在线精品自拍偷免费| 色九九视频| 亚洲色一区二区三区四区| 国产精品一区二区传媒蜜臀| 亚洲午夜精品毛片成人播放| 南皮县| 博乐市| 日韩欧激情一区二区三区| 亚洲码欧洲码一二三四五| 国产成人无码精品久久久露脸| 18禁亚洲一区二区三区| 韩国无码av片在线观看| 天堂俺去俺来也www色官网| 日韩中文字幕v亚洲中文字幕| 精品卡通动漫亚洲AV第一页| 中文字幕一区二区三区四区五区| 日本三级香港三级人妇99| 天堂亚洲免费视频| 国产精品高清中文字幕| 国产色悠悠综合在线观看| 精品一区二区亚洲国产| 国产91精品丝袜美腿在线| 粉嫩一区二区三区国产精品 | 国产91久久精品一区二区|