久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='9sRwa'></tfoot>

  1. <i id='9sRwa'><tr id='9sRwa'><dt id='9sRwa'><q id='9sRwa'><span id='9sRwa'><b id='9sRwa'><form id='9sRwa'><ins id='9sRwa'></ins><ul id='9sRwa'></ul><sub id='9sRwa'></sub></form><legend id='9sRwa'></legend><bdo id='9sRwa'><pre id='9sRwa'><center id='9sRwa'></center></pre></bdo></b><th id='9sRwa'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='9sRwa'><tfoot id='9sRwa'></tfoot><dl id='9sRwa'><fieldset id='9sRwa'></fieldset></dl></div>
      <bdo id='9sRwa'></bdo><ul id='9sRwa'></ul>

    <small id='9sRwa'></small><noframes id='9sRwa'>

    1. <legend id='9sRwa'><style id='9sRwa'><dir id='9sRwa'><q id='9sRwa'></q></dir></style></legend>

      C++ 全局變量聲明

      C++ Global variable declaration(C++ 全局變量聲明)

          <tfoot id='80BcM'></tfoot>
        • <legend id='80BcM'><style id='80BcM'><dir id='80BcM'><q id='80BcM'></q></dir></style></legend>
          1. <i id='80BcM'><tr id='80BcM'><dt id='80BcM'><q id='80BcM'><span id='80BcM'><b id='80BcM'><form id='80BcM'><ins id='80BcM'></ins><ul id='80BcM'></ul><sub id='80BcM'></sub></form><legend id='80BcM'></legend><bdo id='80BcM'><pre id='80BcM'><center id='80BcM'></center></pre></bdo></b><th id='80BcM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='80BcM'><tfoot id='80BcM'></tfoot><dl id='80BcM'><fieldset id='80BcM'></fieldset></dl></div>
              <tbody id='80BcM'></tbody>

            • <small id='80BcM'></small><noframes id='80BcM'>

                <bdo id='80BcM'></bdo><ul id='80BcM'></ul>

                本文介紹了C++ 全局變量聲明的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..


                我想要做的只是在頭文件中定義一個變量,并在兩個不同的 cpp 文件中使用它,而無需在每次包含該頭文件時重新定義該變量
                這是我嘗試的方法:

                變量.h


                What I want to do is just to define a variable in a header file and use it on two different cpp files without redefinition that variable each time I include that header
                Here is how I tried :

                Variables.h

                #ifndef VARIABLES_H // header guards
                #define VARIABLES_H
                
                static bool bShouldRegister;
                
                #endif
                

                (我也試過 extern 但沒有任何改變)

                (I also tried extern but nothing changed)

                在一個 cpp 文件中,我給它一個值 ::bShouldRegister = truebShouldRegister = true;

                And in a cpp file I give it a value ::bShouldRegister = true or bShouldRegister = true;

                在我的另一個 cpp 文件中,我通過創建一個線程并在循環中檢查它的值來檢查它的值(是的,我的線程功能運行良好)

                In my another cpp file I check it's value by creating a thread and check its value in a loop (and yes my thread function works well)

                 while (true)
                 {
                     if (::bShouldRegister) // Or if (bShouldRegister)
                        {
                            MessageBox(NULL,"Value Changed","Done",MB_OK|MB_ICONINFORMATION);
                        }
                  Sleep(100);
                 }
                

                是的,MessageBox 永遠不會出現(bShouldRegister 永遠不會為真:/)

                And yes, that MessageBox never appears (bShouldRegister never gets true :/)

                推薦答案

                必須使用 extern,否則每個翻譯單元中的 bShouldRegister 變量可能不同值.

                You must use extern, otherwise you will have separated bShouldRegister variables in each translation unit with probably different values.

                把它放在一個頭文件(.h)中:

                Put this in a header file (.h):

                extern bool bShouldRegister;
                

                把它放在一個實現文件 (.cpp) 中:

                Put this in one of implementation files (.cpp):

                bool bShouldRegister;
                

                這篇關于C++ 全局變量聲明的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Why do two functions have the same address?(為什么兩個函數的地址相同?)
                Why the initializer of std::function has to be CopyConstructible?(為什么 std::function 的初始化程序必須是可復制構造的?)
                mixing templates with polymorphism(混合模板與多態性)
                When should I use the keyword quot;typenamequot; when using templates(我什么時候應該使用關鍵字“typename?使用模板時)
                Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標準庫)
                gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數模板,而 clang 不能)

                <tfoot id='2yEU4'></tfoot>
                  <tbody id='2yEU4'></tbody>
                  <bdo id='2yEU4'></bdo><ul id='2yEU4'></ul>
                • <legend id='2yEU4'><style id='2yEU4'><dir id='2yEU4'><q id='2yEU4'></q></dir></style></legend>

                  <small id='2yEU4'></small><noframes id='2yEU4'>

                      • <i id='2yEU4'><tr id='2yEU4'><dt id='2yEU4'><q id='2yEU4'><span id='2yEU4'><b id='2yEU4'><form id='2yEU4'><ins id='2yEU4'></ins><ul id='2yEU4'></ul><sub id='2yEU4'></sub></form><legend id='2yEU4'></legend><bdo id='2yEU4'><pre id='2yEU4'><center id='2yEU4'></center></pre></bdo></b><th id='2yEU4'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='2yEU4'><tfoot id='2yEU4'></tfoot><dl id='2yEU4'><fieldset id='2yEU4'></fieldset></dl></div>

                        1. 主站蜘蛛池模板: 在线观看亚洲专区 | 91久久久精品国产一区二区蜜臀 | 成人一区二| 国产精品久久久久久久久久 | 一区二区三区中文 | 精品一区二区三区四区在线 | 欧美一区二区三区精品免费 | 国产视频一区二区 | 亚洲 欧美 日韩 在线 | 亚洲 中文 欧美 日韩 在线观看 | 国产精品18久久久 | 国产精品久久久久久238 | 毛片毛片毛片毛片毛片 | 99热都是精品 | 午夜视频免费在线观看 | 亚洲欧美在线一区 | 精品成人佐山爱一区二区 | 欧美专区日韩专区 | 九九一级片 | 在线高清免费观看视频 | 日日天天 | 国产精品夜色一区二区三区 | 日本在线视频一区二区 | 久久久久久免费毛片精品 | 99久热在线精品视频观看 | 免费高潮视频95在线观看网站 | 国产精品一区二区在线 | 尤物在线精品视频 | 欧美日韩精品在线免费观看 | 成人免费一区二区 | 精品乱子伦一区二区三区 | 国产aa| 特黄特黄a级毛片免费专区 av网站免费在线观看 | 国产精品久久久久久久久免费丝袜 | 久久国产精品视频 | 亚洲精品日韩综合观看成人91 | 欧美精品一区二区三区四区 在线 | 国产免费人成xvideos视频 | 亚洲精品播放 | 日日天天 | 国产精品久久久久久久久久久久 |