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

        <bdo id='N6r1V'></bdo><ul id='N6r1V'></ul>

        <small id='N6r1V'></small><noframes id='N6r1V'>

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

        <legend id='N6r1V'><style id='N6r1V'><dir id='N6r1V'><q id='N6r1V'></q></dir></style></legend>
      1. <tfoot id='N6r1V'></tfoot>
      2. 是什么讓靜態變量只初始化一次?

        What makes a static variable initialize only once?(是什么讓靜態變量只初始化一次?)

          1. <legend id='kvKj8'><style id='kvKj8'><dir id='kvKj8'><q id='kvKj8'></q></dir></style></legend>
              <bdo id='kvKj8'></bdo><ul id='kvKj8'></ul>
            • <small id='kvKj8'></small><noframes id='kvKj8'>

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

                • 本文介紹了是什么讓靜態變量只初始化一次?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我注意到如果你在代碼中用 C++ 初始化一個靜態變量,初始化只會在你第一次運行函數時運行.

                  I noticed that if you initialize a static variable in C++ in code, the initialization only runs the first time you run the function.

                  這很酷,但它是如何實現的?它是否轉化為某種扭曲的 if 語句?(如果給定值,則..)

                  That is cool, but how is that implemented? Does it translate to some kind of twisted if statement? (if given a value, then ..)

                  void go( int x )
                  {
                      static int j = x ;
                      cout << ++j << endl ; // see 6, 7, 8
                  } 
                  
                  int main()
                  {
                      go( 5 ) ;
                      go( 5 ) ;
                      go( 5 ) ; 
                  }
                  

                  推薦答案

                  是的,它通常會轉換為帶有內部布爾標志的隱式 if 語句.因此,在最基本的實現中,您的聲明通常會轉換為類似

                  Yes, it does normally translate into an implicit if statement with an internal boolean flag. So, in the most basic implementation your declaration normally translates into something like

                  void go( int x ) {
                    static int j;
                    static bool j_initialized;
                  
                    if (!j_initialized) {
                      j = x;
                      j_initialized = true;
                    }
                  
                    ...
                  } 
                  

                  最重要的是,如果您的靜態對象具有非平凡的析構函數,則語言必須遵守另一條規則:此類靜態對象必須以其構造的相反順序進行析構.由于構造順序僅在運行時已知,因此銷毀順序也在運行時定義.所以,每次你用非平凡的析構函數構造一個局部靜態對象時,程序都必須將它注冊到某種線性容器中,稍后它將用來以適當的順序析構這些對象.

                  On top of that, if your static object has a non-trivial destructor, the language has to obey another rule: such static objects have to be destructed in the reverse order of their construction. Since the construction order is only known at run-time, the destruction order becomes defined at run-time as well. So, every time you construct a local static object with non-trivial destructor, the program has to register it in some kind of linear container, which it will later use to destruct these objects in proper order.

                  不用說,實際細節取決于實現.

                  Needless to say, the actual details depend on implementation.

                  值得補充的是,當涉及使用編譯時常量初始化的原始"類型的靜態對象(如您的示例中的 int)時,編譯器可以在啟動時自由地初始化該對象.你永遠不會注意到差異.但是,如果您使用非原始"對象來舉一個更復雜的示例

                  It is worth adding that when it comes to static objects of "primitive" types (like int in your example) initialized with compile-time constants, the compiler is free to initialize that object at startup. You will never notice the difference. However, if you take a more complicated example with a "non-primitive" object

                  void go( int x ) {
                    static std::string s = "Hello World!";
                    ...
                  

                  那么上述帶有 if 的方法是您應該期望在生成的代碼中找到的,即使對象是用編譯時常量初始化的.

                  then the above approach with if is what you should expect to find in the generated code even when the object is initialized with a compile-time constant.

                  在您的情況下,初始化程序在編譯時未知,這意味著編譯器必須延遲初始化并使用隱式 if.

                  In your case the initializer is not known at compile time, which means that the compiler has to delay the initialization and use that implicit if.

                  這篇關于是什么讓靜態變量只初始化一次?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 不能)
                  <i id='gID6e'><tr id='gID6e'><dt id='gID6e'><q id='gID6e'><span id='gID6e'><b id='gID6e'><form id='gID6e'><ins id='gID6e'></ins><ul id='gID6e'></ul><sub id='gID6e'></sub></form><legend id='gID6e'></legend><bdo id='gID6e'><pre id='gID6e'><center id='gID6e'></center></pre></bdo></b><th id='gID6e'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='gID6e'><tfoot id='gID6e'></tfoot><dl id='gID6e'><fieldset id='gID6e'></fieldset></dl></div>
                    <bdo id='gID6e'></bdo><ul id='gID6e'></ul>

                      • <legend id='gID6e'><style id='gID6e'><dir id='gID6e'><q id='gID6e'></q></dir></style></legend>
                          <tbody id='gID6e'></tbody>
                      • <tfoot id='gID6e'></tfoot>

                          • <small id='gID6e'></small><noframes id='gID6e'>

                            主站蜘蛛池模板: 国产精品一区视频 | 久久久久久久一区 | 久久精品在线免费视频 | 99精品欧美一区二区蜜桃免费 | 国产一区二区三区 | 日韩亚洲欧美一区 | 99热99| 欧美日韩成人在线 | 久久国产精99精产国高潮 | www.4hu影院| 国产探花在线精品一区二区 | 91视频免费视频 | 国产久| 精品亚洲一区二区 | 欧美一区二区三区在线免费观看 | 国产男女精品 | 亚洲有码转帖 | 精品蜜桃一区二区三区 | www.4567| 国产精品成人久久久久a级 久久蜜桃av一区二区天堂 | 在线男人天堂 | 国产一区二区高清在线 | 91久久久久久久 | h片在线免费看 | 成人在线精品 | 亚洲视频在线播放 | 精国产品一区二区三区四季综 | 久久亚洲一区 | 九九九视频在线 | 亚洲天堂精品久久 | 九九综合九九 | 狠狠干夜夜草 | 亚洲不卡 | 国产精品久久久久久久久久 | 99国内精品| 国产精品免费在线 | 国产精品无码永久免费888 | 亚洲情综合五月天 | 亚洲看片 | 亚洲在线观看视频 | 亚洲欧美在线视频 |