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

  • <tfoot id='49Bp1'></tfoot>

      • <bdo id='49Bp1'></bdo><ul id='49Bp1'></ul>

        <small id='49Bp1'></small><noframes id='49Bp1'>

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

        基于繼承類的模板特化

        Template specialization based on inherit class(基于繼承類的模板特化)
        <tfoot id='3J6jo'></tfoot>
            <tbody id='3J6jo'></tbody>

            <bdo id='3J6jo'></bdo><ul id='3J6jo'></ul>

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

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

                2. 本文介紹了基于繼承類的模板特化的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我想讓這個專門的不改變主.是否可以根據其基類專門化某些東西?我希望如此.

                  I want to make this specialized w/o changing main. Is it possible to specialize something based on its base class? I hope so.

                  -編輯-

                  我將有幾個繼承自 SomeTag 的類.我不想為他們每個人編寫相同的專業.

                  I'll have several classes that inherit from SomeTag. I don't want to write the same specialization for each of them.

                  class SomeTag {};
                  class InheritSomeTag : public SomeTag {};
                  
                  template <class T, class Tag=T>
                  struct MyClass
                  {
                  };
                  
                  template <class T>
                  struct MyClass<T, SomeTag>
                  {
                      typedef int isSpecialized;
                  };
                  
                  int main()
                  {
                      MyClass<SomeTag>::isSpecialized test1; //ok
                      MyClass<InheritSomeTag>::isSpecialized test2; //how do i make this specialized w/o changing main()
                      return 0;
                  }
                  

                  推薦答案

                  這篇文章描述了一個巧妙的技巧:http://www.gotw.ca/publications/mxc++-item-4.htm

                  This article describes a neat trick: http://www.gotw.ca/publications/mxc++-item-4.htm

                  這是基本思想.您首先需要一個 IsDerivedFrom 類(它提供運行時和編譯時檢查):

                  Here's the basic idea. You first need an IsDerivedFrom class (this provides runtime and compile-time checking):

                  template<typename D, typename B>
                  class IsDerivedFrom
                  {
                    class No { };
                    class Yes { No no[3]; }; 
                  
                    static Yes Test( B* ); // not defined
                    static No Test( ... ); // not defined 
                  
                    static void Constraints(D* p) { B* pb = p; pb = p; } 
                  
                  public:
                    enum { Is = sizeof(Test(static_cast<D*>(0))) == sizeof(Yes) }; 
                  
                    IsDerivedFrom() { void(*p)(D*) = Constraints; }
                  };
                  

                  那么你的 MyClass 需要一個潛在的特殊實現:

                  Then your MyClass needs an implementation that's potentially specialized:

                  template<typename T, int>
                  class MyClassImpl
                  {
                    // general case: T is not derived from SomeTag
                  }; 
                  
                  template<typename T>
                  class MyClassImpl<T, 1>
                  {
                    // T is derived from SomeTag
                    public:
                       typedef int isSpecialized;
                  }; 
                  

                  和 MyClass 實際上看起來像:

                  and MyClass actually looks like:

                  template<typename T>
                  class MyClass: public MyClassImpl<T, IsDerivedFrom<T, SomeTag>::Is>
                  {
                  };
                  

                  那么你的主菜就可以了:

                  Then your main will be fine the way it is:

                  int main()
                  {
                      MyClass<SomeTag>::isSpecialized test1; //ok
                      MyClass<InheritSomeTag>::isSpecialized test2; //ok also
                      return 0;
                  }
                  

                  這篇關于基于繼承類的模板特化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 不能)

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

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

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

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

                          <tfoot id='JahV3'></tfoot>
                              <tbody id='JahV3'></tbody>
                            主站蜘蛛池模板: 国产精品99久久久精品免费观看 | 亚洲视频免费在线观看 | 欧美黄色一区 | 成人精品福利 | 免费看一区二区三区 | 成人一区二区视频 | 亚洲综合在线视频 | 久热久草| 久久99精品久久久久 | 日韩福利| 成人精品一区二区三区 | www.亚洲国产精品 | 一区二区福利视频 | 爱草视频 | 国产一级片一区二区 | 欧美日韩在线观看视频 | 精品国产乱码久久久久久88av | 亚洲综合一区二区三区 | av中文在线| 国产精品99久久久久久久久久久久 | 天天影视网天天综合色在线播放 | a级大片免费观看 | 国产精品不卡一区 | 黄色免费观看网站 | 久久狠狠| 国产玖玖 | 一区二区三区日本 | 国产精品jizz在线观看老狼 | 能看的av| 伊人久操 | 亚洲成人高清 | av中文字幕在线 | 成人国产精品久久久 | 久久精品免费观看 | 久草免费在线视频 | 国产精品自拍啪啪 | 黄色片在线观看网址 | 欧美激情综合 | www国产亚洲精品 | 久久综合久久自在自线精品自 | 国产精品久久久久久久久久 |