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

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

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

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

      <tfoot id='xgVWV'></tfoot>
    1. 如果我只想在模板中專門化一種方法,我該怎么

      If I want to specialise just one method in a template, how do I do it?(如果我只想在模板中專門化一種方法,我該怎么做?)
        1. <small id='CAL5r'></small><noframes id='CAL5r'>

          <tfoot id='CAL5r'></tfoot>
            <tbody id='CAL5r'></tbody>

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

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

                <i id='CAL5r'><tr id='CAL5r'><dt id='CAL5r'><q id='CAL5r'><span id='CAL5r'><b id='CAL5r'><form id='CAL5r'><ins id='CAL5r'></ins><ul id='CAL5r'></ul><sub id='CAL5r'></sub></form><legend id='CAL5r'></legend><bdo id='CAL5r'><pre id='CAL5r'><center id='CAL5r'></center></pre></bdo></b><th id='CAL5r'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='CAL5r'><tfoot id='CAL5r'></tfoot><dl id='CAL5r'><fieldset id='CAL5r'></fieldset></dl></div>
              1. 本文介紹了如果我只想在模板中專門化一種方法,我該怎么做?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                限時(shí)送ChatGPT賬號..

                假設(shè)我有一個(gè)模板類

                template <typename T> struct Node
                {
                    // general method split
                    void split()
                    {
                        // ... actual code here (not empty)
                    }
                };
                

                需要在 Triangle 類的情況下專門化這個(gè)......類似

                Need to specialise this in the Triangle class case.. something like

                template <>
                struct Node <Triangle*>
                {
                    // specialise the split method
                    void split() {}
                } ;
                

                但我不想想重新重寫整個(gè)模板!唯一需要更改的是 split() 方法,僅此而已.

                but I don't want to rewrite the entire template over again! The only thing that needs to change is the split() method, nothing more.

                推薦答案

                您可以在類聲明之外僅為該函數(shù)提供專門化.

                You can provide a specialization for only that function outside the class declaration.

                template <typename T> struct Node
                {
                    // general method split
                    void split()
                    {
                        // implementation here or somewhere else in header
                    }
                };
                

                //cpp中聲明的函數(shù)原型void splitIntNode( Node & node );

                // prototype of function declared in cpp void splitIntNode( Node & node );

                template <>
                void Node<int>::split()
                {
                     splitIntNode( this ); // which can be implemented
                }
                
                int main(int argc, char* argv[])
                {
                   Node <char> x;
                   x.split(); //will call original method
                   Node <int> k;
                   k.split(); //will call the method for the int version
                }
                

                如果 splitIntNode 需要訪問私有成員,您可以將這些成員傳遞給函數(shù)而不是整個(gè)節(jié)點(diǎn).

                If splitIntNode needs access to private members, you can just pass those members into the function rather than the whole Node.

                這篇關(guān)于如果我只想在模板中專門化一種方法,我該怎么做?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guān)文檔推薦

                Why do two functions have the same address?(為什么兩個(gè)函數(shù)的地址相同?)
                Why the initializer of std::function has to be CopyConstructible?(為什么 std::function 的初始化程序必須是可復(fù)制構(gòu)造的?)
                mixing templates with polymorphism(混合模板與多態(tài)性)
                When should I use the keyword quot;typenamequot; when using templates(我什么時(shí)候應(yīng)該使用關(guān)鍵字“typename?使用模板時(shí))
                Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標(biāo)準(zhǔn)庫)
                gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數(shù)模板,而 clang 不能)
                  1. <tfoot id='BXpPk'></tfoot>
                    <i id='BXpPk'><tr id='BXpPk'><dt id='BXpPk'><q id='BXpPk'><span id='BXpPk'><b id='BXpPk'><form id='BXpPk'><ins id='BXpPk'></ins><ul id='BXpPk'></ul><sub id='BXpPk'></sub></form><legend id='BXpPk'></legend><bdo id='BXpPk'><pre id='BXpPk'><center id='BXpPk'></center></pre></bdo></b><th id='BXpPk'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='BXpPk'><tfoot id='BXpPk'></tfoot><dl id='BXpPk'><fieldset id='BXpPk'></fieldset></dl></div>
                      <bdo id='BXpPk'></bdo><ul id='BXpPk'></ul>
                        <tbody id='BXpPk'></tbody>

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

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

                          主站蜘蛛池模板: 天天综合网站 | 激情综合五月婷婷 | 亚洲v视频 | 性色av一区二区三区 | 四虎在线观看 | 六月激情婷婷 | a在线免费观看 | 三级理论片 | 精品免费国产 | 日韩欧美一区在线 | 国产性色av | 精品亚洲国产成人av制服丝袜 | 自拍偷拍中文字幕 | 91精品国产成人www | 99久久国产视频 | 国产剧情在线 | 亚洲一区成人 | 精品伊人久久 | 日韩毛片视频 | 欧美亚洲一区二区三区 | 激情六月天 | 免费色视频 | 国产传媒一区二区 | 欧美精品第一页 | 国产综合视频在线观看 | 欧美国产一区二区 | 日本三级在线视频 | 91性高潮久久久久久久久 | 欧美国产日韩在线 | 亚洲福利一区 | 亚洲国产成人在线 | 五月天婷婷社区 | av不卡一区 | 日韩中文字幕在线观看 | 成人国产| 日韩欧美在线视频观看 | 黄网在线免费观看 | 国产区一区二区 | 国产精品一区二区三区免费 | 国产对白videos麻豆高潮 | 久久国产精品一区二区三区 |