久久久久久久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. 本文介紹了如果我只想在模板中專門化一種方法,我該怎么做?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                限時送ChatGPT賬號..

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

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

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

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

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

                但我不想想重新重寫整個模板!唯一需要更改的是 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ù)而不是整個節(jié)點.

                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?(為什么兩個函數(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(我什么時候應(yīng)該使用關(guān)鍵字“typename?使用模板時)
                Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標準庫)
                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'>

                          主站蜘蛛池模板: 日韩精品一区二区三区四区 | 色视频免费 | 国产精品久久久久一区二区三区 | 久久免费观看一级毛片 | 欧美看片 | 国产精品观看 | 国产精品久久久久久久久久 | 九九九视频在线观看 | 日韩免费网站 | 亚洲视频在线一区 | 久久国产视频网站 | 日韩一区二区在线视频 | 91精品国产91久久久久久 | 在线观看成人 | 国产精品久久国产精品 | 国产a区| 久久久新视频 | 精品福利在线 | av中文字幕在线观看 | 国产精品美女在线观看 | 亚洲精品久久久久久一区二区 | 欧美一区视频在线 | 国产一区二区三区视频 | 天堂三级 | 亚洲精品久久久久国产 | 国产免费一区二区三区 | 91黄色免费看 | 日韩久久精品 | 欧美二三区 | 91国内产香蕉 | 一区视频 | 91福利影院 | 在线第一页 | 久久久久国产一区二区三区 | 福利视频网站 | 亚洲一区二区在线播放 | 91精品国产色综合久久不卡蜜臀 | 欧美一级片a | 中文字幕一区在线观看视频 | 91正在播放 | 成人av资源在线 |