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

    • <bdo id='RLyW0'></bdo><ul id='RLyW0'></ul>
    1. <legend id='RLyW0'><style id='RLyW0'><dir id='RLyW0'><q id='RLyW0'></q></dir></style></legend>

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

        <tfoot id='RLyW0'></tfoot>

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

        為什么兩個函數的地址相同?

        Why do two functions have the same address?(為什么兩個函數的地址相同?)

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

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

              <bdo id='3tZFS'></bdo><ul id='3tZFS'></ul>
                <tbody id='3tZFS'></tbody>

                  <i id='3tZFS'><tr id='3tZFS'><dt id='3tZFS'><q id='3tZFS'><span id='3tZFS'><b id='3tZFS'><form id='3tZFS'><ins id='3tZFS'></ins><ul id='3tZFS'></ul><sub id='3tZFS'></sub></form><legend id='3tZFS'></legend><bdo id='3tZFS'><pre id='3tZFS'><center id='3tZFS'></center></pre></bdo></b><th id='3tZFS'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='3tZFS'><tfoot id='3tZFS'></tfoot><dl id='3tZFS'><fieldset id='3tZFS'></fieldset></dl></div>
                • 本文介紹了為什么兩個函數的地址相同?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  考慮這個函數模板:

                  template<typename T>
                  unsigned long f(void *) { return 0;}
                  

                  現在,我將 ff 的地址打印為:

                  Now, I print the addresses of f<A> and f<B> as:

                  std::cout << (void*)f<A> << std::endl;
                  std::cout << (void*)f<B> << std::endl;
                  

                  如果在 MSVS10 中編譯,為什么它們打印相同的地址?它們不是兩個不同的功能,因此應該打印不同的地址嗎?

                  Why do they print the same address if compiled in MSVS10? Are they not two different functions and therefore should print different addresses?

                  更新:

                  我意識到在 ideone 上,它會打印不同的地址.MSVS10 優化了代碼,因為該函數不以任何方式依賴 T,因此它產生相同的函數.@Mark 對此的回答和評論很有價值.:-)

                  I realized that on ideone, it prints the different address. MSVS10 optimizes the code, as the function doesn't depend on T in any way, so it produces same function. @Mark's answer and comments on this are valuable. :-)

                  推薦答案

                  由于函數不依賴模板參數,編譯器可以將所有實例化為一個函數.

                  Since the function doesn't depend on the template parameter, the compiler can condense all instantiations into a single function.

                  我不知道你為什么得到 1 作為地址.

                  I don't know why you get 1 for the address.

                  我用我的真實代碼進行了試驗,并得出結論,@Mark 上面所說的在這里非常重要:

                  I experimented with my real code, and concluded that what @Mark said above is very important here :

                  由于函數不依賴于模板參數,編譯器可以將所有實例化為一個函數.

                  我還得出一個結論,如果函數體依賴于T*,而不是T,它仍然為我的不同類型參數生成相同的函數真正的代碼(雖然不是在 ideone 上).然而,如果它依賴于 T,那么它會產生不同的函數,因為 sizeof(T) 對于不同的類型參數是不同的(對我來說很幸運).

                  I also came to a conclusion that if the function-body depends on T*, not on T, it still produces the same function for different type arguments in my real code (not on ideone, though). However, if it depends on T, then it produces different functions, because sizeof(T) differs (fortunately for me) for different type arguments.

                  所以我在函數模板中添加了一個 T 類型的虛擬 automatic 變量,這樣函數就可以依賴于 T 的大小從而強制它產生不同的功能.

                  So I added a dummy automatic variable of type T in the function template, so that the function could depend on the size of T so as to force it to produce different functions.

                  這篇關于為什么兩個函數的地址相同?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  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 不能)
                  Strong typedefs(強類型定義)

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

                          <tfoot id='tgDcP'></tfoot>
                        2. <legend id='tgDcP'><style id='tgDcP'><dir id='tgDcP'><q id='tgDcP'></q></dir></style></legend>

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

                            主站蜘蛛池模板: 欧美成人免费 | 午夜精品久久久久久久99黑人 | 欧美日韩一区不卡 | 中文字幕1区 | 日韩免费一区二区 | aa级毛片毛片免费观看久 | 日韩a视频| 日本精品免费在线观看 | 三级av网址 | 久草网免费| 欧美日一区二区 | 久草网站 | 天天舔天天 | 性色av一区 | 国产一级免费视频 | 亚洲欧美视频 | 久草新在线| 理论片免费在线观看 | caoporn视频 | 精品视频在线观看 | 久久专区 | 国产亚洲精品久久久久动 | 天天成人综合网 | 亚洲视频一区二区三区四区 | 在线成人一区 | 久久精品国产久精国产 | 黄网站免费在线看 | 婷婷综合 | 午夜综合 | 日韩视频区 | 黄色毛片网站在线观看 | www.色五月.com | 国产精品视频在线免费观看 | 亚洲电影中文字幕 | 91精品久久久久久久久中文字幕 | 中文字幕精品一区二区三区精品 | h漫在线观看 | 久草青青 | 成人免费大片黄在线播放 | 亚洲伊人久久综合 | 一区在线观看视频 |