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

<legend id='fkMYF'><style id='fkMYF'><dir id='fkMYF'><q id='fkMYF'></q></dir></style></legend>

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

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

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

    <tfoot id='fkMYF'></tfoot>

    1. 為什么 C++ 模板定義需要在頭文件中?

      Why do C++ template definitions need to be in the header?(為什么 C++ 模板定義需要在頭文件中?)
        <tbody id='QBo9P'></tbody>

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

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

                <legend id='QBo9P'><style id='QBo9P'><dir id='QBo9P'><q id='QBo9P'></q></dir></style></legend>
              1. 本文介紹了為什么 C++ 模板定義需要在頭文件中?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                可能的重復:
                為什么應該模板類的實現和聲明在同一個頭文件中?

                例如在定義模板類時,為什么類方法的實現需要在標題中?為什么它們不能在實現文件 (cpp/cxx) 中?

                e.g when defining a template class why do the implementations of the class methods need to be in the header? Why can't they be in a implementation file (cpp/cxx)?

                推薦答案

                模板類不是類,而是可用于創建類的模板.當你實例化這樣一個類時,例如MyTemplate,編譯器當場創建類.為了創建它,它必須查看所有模板化的成員函數(以便它可以使用模板創建實際的成員函數,例如 MyTemplate::foo() ),因此這些模板化的成員函數必須在頭文件中.

                A template class is not a class, it's a template that can be used to create a class. When you instantiate such a class, e.g. MyTemplate<int>, the compiler creates the class on the spot. In order to create it, it has to see all the templated member functions (so that it can use the templates to create actual member functions such as MyTemplate<int>::foo() ), and therefore these templated member functions must be in the header.

                如果成員不在頭文件中,編譯器將簡單地假設它們存在于其他地方,并從模板化的函數聲明中創建實際的函數聲明,這會導致鏈接器錯誤.

                If the members are not in the header, the compiler will simply assume that they exist somewhere else and just create actual function declarations from the templated function declarations, and this gives you linker errors.

                "export" 關鍵字應該可以解決這個問題,但很少有編譯器支持它(我只知道 Comeau).

                The "export" keyword is supposed to fix this, but few compilers support it (I only know of Comeau).

                您也可以顯式實例化 MyTemplate - 然后編譯器會在編譯包含 MyTemplate 成員函數定義模板.

                You can also explicitly instantiate MyTemplate<int> - then the compiler will create actual member functions for MyTemplate<int> when it compiles the cpp files containing the MyTemplate member function definition templates.

                這篇關于為什么 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 不能)

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

                      • <bdo id='TsoZt'></bdo><ul id='TsoZt'></ul>

                          <legend id='TsoZt'><style id='TsoZt'><dir id='TsoZt'><q id='TsoZt'></q></dir></style></legend>

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

                            <tbody id='TsoZt'></tbody>
                        1. 主站蜘蛛池模板: 欧美在线播放视频 | 国产黄色一区 | 亚洲一区二区欧美 | 欧美日韩一区二区在线 | 日本伊人网 | 一区二区三区四区视频 | 97cao| 操出白浆视频 | 欧美色偷偷 | 国产精品不卡视频 | 96久久| 日韩av网站在线观看 | av在线免费观看网址 | 久久高清免费视频 | 欧美精品区| avxxxxx| 国产福利91精品一区二区三区 | 成年人视频在线播放 | 日本福利在线 | 中文字幕在线观看一区二区 | 日本天堂网 | 色黄大色黄女片免费中国 | 免费一区二区三区 | 国产成人在线免费视频 | 亚洲人成在线观看 | 成人在线黄色 | 久草视频免费在线观看 | 天天干天天草 | 在线视频成人 | av超碰在线 | 欧美成人精品一区二区三区 | 视频爱爱免费视频爱爱太爽 | 国产专区在线播放 | 成年人网站在线免费观看 | 国产精品久久久国产盗摄 | 国产欧美日韩在线观看 | 九九在线 | 久久精品欧美一区二区 | 手机看片福利永久 | 国产在线视频91 | 亚洲欧美日韩一区 |