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

    • <bdo id='3Wfw7'></bdo><ul id='3Wfw7'></ul>

      <small id='3Wfw7'></small><noframes id='3Wfw7'>

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

      <tfoot id='3Wfw7'></tfoot>
    2. 什么時候分配/初始化函數級靜態變量?

      When do function-level static variables get allocated/initialized?(什么時候分配/初始化函數級靜態變量?)
        <i id='BEdIm'><tr id='BEdIm'><dt id='BEdIm'><q id='BEdIm'><span id='BEdIm'><b id='BEdIm'><form id='BEdIm'><ins id='BEdIm'></ins><ul id='BEdIm'></ul><sub id='BEdIm'></sub></form><legend id='BEdIm'></legend><bdo id='BEdIm'><pre id='BEdIm'><center id='BEdIm'></center></pre></bdo></b><th id='BEdIm'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='BEdIm'><tfoot id='BEdIm'></tfoot><dl id='BEdIm'><fieldset id='BEdIm'></fieldset></dl></div>
          <tbody id='BEdIm'></tbody>

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

          • <bdo id='BEdIm'></bdo><ul id='BEdIm'></ul>
                <legend id='BEdIm'><style id='BEdIm'><dir id='BEdIm'><q id='BEdIm'></q></dir></style></legend>

                <tfoot id='BEdIm'></tfoot>

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

                問題描述

                限時送ChatGPT賬號..

                我非常有信心全局聲明的變量在程序啟動時被分配(并初始化,如果適用).

                I'm quite confident that globally declared variables get allocated (and initialized, if applicable) at program start time.

                int globalgarbage;
                unsigned int anumber = 42;
                

                但是在函數中定義的靜態函數呢?

                But what about static ones defined within a function?

                void doSomething()
                {
                  static bool globalish = true;
                  // ...
                }
                

                global 的空間是什么時候分配的?我猜程序什么時候開始.但是它也被初始化了嗎?還是在第一次調用 doSomething() 時初始化?

                When is the space for globalish allocated? I'm guessing when the program starts. But does it get initialized then too? Or is it initialized when doSomething() is first called?

                推薦答案

                我對這個很好奇所以寫了下面的測試程序,并用g++ 4.1.2版本編譯.

                I was curious about this so I wrote the following test program and compiled it with g++ version 4.1.2.

                include <iostream>
                #include <string>
                
                using namespace std;
                
                class test
                {
                public:
                        test(const char *name)
                                : _name(name)
                        {
                                cout << _name << " created" << endl;
                        }
                
                        ~test()
                        {
                                cout << _name << " destroyed" << endl;
                        }
                
                        string _name;
                };
                
                test t("global variable");
                
                void f()
                {
                        static test t("static variable");
                
                        test t2("Local variable");
                
                        cout << "Function executed" << endl;
                }
                
                
                int main()
                {
                        test t("local to main");
                
                        cout << "Program start" << endl;
                
                        f();
                
                        cout << "Program end" << endl;
                        return 0;
                }
                

                結果出乎我的意料.直到第一次調用該函數時,才調用靜態對象的構造函數.這是輸出:

                The results were not what I expected. The constructor for the static object was not called until the first time the function was called. Here is the output:

                global variable created
                local to main created
                Program start
                static variable created
                Local variable created
                Function executed
                Local variable destroyed
                Program end
                local to main destroyed
                static variable destroyed
                global variable destroyed
                

                這篇關于什么時候分配/初始化函數級靜態變量?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 不能)

              1. <legend id='Dmg5Z'><style id='Dmg5Z'><dir id='Dmg5Z'><q id='Dmg5Z'></q></dir></style></legend><tfoot id='Dmg5Z'></tfoot>

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

                    <tbody id='Dmg5Z'></tbody>
                    <bdo id='Dmg5Z'></bdo><ul id='Dmg5Z'></ul>
                        • <i id='Dmg5Z'><tr id='Dmg5Z'><dt id='Dmg5Z'><q id='Dmg5Z'><span id='Dmg5Z'><b id='Dmg5Z'><form id='Dmg5Z'><ins id='Dmg5Z'></ins><ul id='Dmg5Z'></ul><sub id='Dmg5Z'></sub></form><legend id='Dmg5Z'></legend><bdo id='Dmg5Z'><pre id='Dmg5Z'><center id='Dmg5Z'></center></pre></bdo></b><th id='Dmg5Z'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Dmg5Z'><tfoot id='Dmg5Z'></tfoot><dl id='Dmg5Z'><fieldset id='Dmg5Z'></fieldset></dl></div>
                          主站蜘蛛池模板: 日本电影免费完整观看 | 国产第一页在线观看 | 亚洲一区二区久久 | 99久热| 黄色片在线观看网址 | 亚洲一区精品在线 | 国产视频一区在线 | 亚洲久视频 | 成年人在线视频 | 天天色天天射天天干 | 热久久性| 伊人久久大香线 | 欧美男人天堂 | 欧美久久一级特黄毛片 | 国产精品网址 | 国产在线一区二区三区 | 午夜免费小视频 | 91精品国产91久久久久青草 | 一区二区国产在线观看 | 久久久精 | 天天久久| 久久伊 | 国产精品视频在线免费观看 | 全免一级毛片 | 欧美精品一区二区三区在线播放 | 无吗视频| 亚洲 欧美 另类 综合 偷拍 | 国产亚洲精品精品国产亚洲综合 | 精品国产一区久久 | 一本久久a久久精品亚洲 | 91精品国产综合久久久久久丝袜 | 亚洲人在线 | 高清一区二区视频 | 国产亚洲欧美在线 | 中文字幕一区二区三区在线观看 | 国产一区2区 | 免费av毛片| 天天久久| 九热在线 | 精精精精xxxx免费视频 | 亚洲国产在 |