久久久久久久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. 主站蜘蛛池模板: 国产精品一区在线观看 | 亚洲久草 | 亚洲免费一区 | 99在线免费观看视频 | 久色视频在线 | 亚洲精品一区二三区不卡 | 一a一片一级一片啪啪 | 国产精品久久久久久久久久久久久 | 午夜精品久久久久久久久久久久久 | 精品一二三区 | 一区二区三区四区免费在线观看 | 天天草天天爱 | 亚洲国产一| 国产成人精品午夜视频免费 | 免费观看成人性生生活片 | 黄色毛片视频 | 91传媒在线观看 | 国产精品久久av | 午夜视频免费在线观看 | 国产欧美日韩在线观看 | 一区二区三区成人 | 四虎影院在线观看av | 久久精品久久久 | 国产精品久久久久久一区二区三区 | 日韩精品1区2区3区 成人黄页在线观看 | 日韩精品1区2区3区 爱爱综合网 | 精品一区二区三区中文字幕 | 日日久 | 中文字幕日韩三级 | 久久久国产精品 | 中文字幕在线视频精品 | 色综合色综合色综合 | 日本中文在线 | 中文天堂在线一区 | 久久狼人天堂 | 北条麻妃av一区二区三区 | 久久精品色视频 | 免费久久精品视频 | 91精品国产乱码久久蜜臀 | 国产一区精品 | 一区精品国产欧美在线 |