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

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

      <tfoot id='EREi3'></tfoot>
    1. <legend id='EREi3'><style id='EREi3'><dir id='EREi3'><q id='EREi3'></q></dir></style></legend>
        • <bdo id='EREi3'></bdo><ul id='EREi3'></ul>

        <i id='EREi3'><tr id='EREi3'><dt id='EREi3'><q id='EREi3'><span id='EREi3'><b id='EREi3'><form id='EREi3'><ins id='EREi3'></ins><ul id='EREi3'></ul><sub id='EREi3'></sub></form><legend id='EREi3'></legend><bdo id='EREi3'><pre id='EREi3'><center id='EREi3'></center></pre></bdo></b><th id='EREi3'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='EREi3'><tfoot id='EREi3'></tfoot><dl id='EREi3'><fieldset id='EREi3'></fieldset></dl></div>
      1. 類模板中的模板構造函數 - 如何為第二個參數顯

        Template constructor in a class template - how to explicitly specify template argument for the 2nd parameter?(類模板中的模板構造函數 - 如何為第二個參數顯式指定模板參數?)
          <tbody id='lxVtZ'></tbody>
        <i id='lxVtZ'><tr id='lxVtZ'><dt id='lxVtZ'><q id='lxVtZ'><span id='lxVtZ'><b id='lxVtZ'><form id='lxVtZ'><ins id='lxVtZ'></ins><ul id='lxVtZ'></ul><sub id='lxVtZ'></sub></form><legend id='lxVtZ'></legend><bdo id='lxVtZ'><pre id='lxVtZ'><center id='lxVtZ'></center></pre></bdo></b><th id='lxVtZ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='lxVtZ'><tfoot id='lxVtZ'></tfoot><dl id='lxVtZ'><fieldset id='lxVtZ'></fieldset></dl></div>

        1. <legend id='lxVtZ'><style id='lxVtZ'><dir id='lxVtZ'><q id='lxVtZ'></q></dir></style></legend>

              • <bdo id='lxVtZ'></bdo><ul id='lxVtZ'></ul>
                1. <small id='lxVtZ'></small><noframes id='lxVtZ'>

                  <tfoot id='lxVtZ'></tfoot>

                  本文介紹了類模板中的模板構造函數 - 如何為第二個參數顯式指定模板參數?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  類模板中的模板構造函數 - 如何為第二個參數顯式指定模板參數?

                  Template constructor in a class template - how to explicitly specify template argument for the 2nd parameter?

                  嘗試為構造函數 2 顯式指定模板參數時出現編譯錯誤.如果我真的想顯式調用構造函數 2 應該怎么做?

                  compile error when tried to explicit specify template argument for constructor 2. How should I do it if I really want to explicit call constructor 2 ?

                  請注意,當您要明確指定刪除器類型時,這與 boost::shared_ptr 的情況相同.

                  Please note this is the same situation for boost::shared_ptr when you want to explicitly specify the deleter type.

                  注意對于-構造函數foo(),明確指定工作正常.

                  N.B. For non-construction function foo(), explicitly specify works fine.

                  N.B 我知道它工作正常沒有為構造函數 2 明確指定第二個作為模板參數推導通常工作正常,我只是好奇如何明確指定它.

                  N.B I know it works fine without specify the 2nd one explicitly for the constructor 2 as template argument deduction normally just works fine, I am just curious how to specify it explicitly.

                  template<class T> class TestTemplate {
                  public:
                      //constructor 1
                      template<class Y> TestTemplate(T * p) {
                          cout << "c1" << endl;
                      }
                  
                      //constructor 2
                      template<class Y, class D> TestTemplate(Y * p, D d) {
                          cout << "c2" << endl;
                      }
                  
                      template<class T, class B>
                      void foo(T a, B b) {
                          cout << "foo" << endl;
                      }
                  };
                  
                  int main() {
                      TestTemplate<int> tp(new int());//this one works ok call constructor 1
                      //explicit template argument works ok
                      tp.foo<int*, string>(new int(), "hello");
                  
                      TestTemplate<int> tp2(new int(),2);//this one works ok call constructor 2
                  
                      //compile error when tried to explicit specify template argument for constructor 2
                      //How should I do it if I really want to explicit call constructor 2?
                      //TestTemplate<int*, int> tp3(new int(), 2); //wrong
                      //TestTemplate<int*> tp3<int*,int>(new int(), 2); //wrong again
                  
                      return 0;
                  }
                  

                  推薦答案

                  修復您的代碼,以下內容將起作用:

                  Fixing your code, the following would work:

                  template<class T> class TestTemplate {
                  public:
                      //constructor 1
                      template<class Y> TestTemplate(Y * p) {
                          cout << "c1" << endl;
                      }
                  
                      //constructor 2
                      template<class Y, class D> TestTemplate(Y * p, D d) {
                          cout << "c2" << endl;
                      }
                  
                      template<class A, class B>
                      void foo(A a, B b) {
                          cout << "foo" << endl;
                      }
                  };
                  
                  int main() {
                      TestTemplate<int> tp(new int());
                  
                      tp.foo<int*, string>(new int(), "hello");
                  
                      TestTemplate<int> tp2(new int(),2);
                  }
                  

                  您不能將 T 用于類模板參數 構造函數模板參數.但是,要回答您的問題,來自 [14.5.2p5]:

                  You cannot use T for the class template parameter and the constructor template parameter. But, to answer your question, from [14.5.2p5]:

                  因為顯式模板參數列表跟在函數后面模板名稱,因為轉換成員函數模板和調用構造函數成員函數模板時不使用函數名,無法提供顯式模板這些函數模板的參數列表.

                  Because the explicit template argument list follows the function template name, and because conversion member function templates and constructor member function templates are called without using a function name, there is no way to provide an explicit template argument list for these function templates.

                  因此,您不能為構造函數顯式指定模板參數.

                  Therefore, you cannot explicitly specify template arguments for constructor.

                  這篇關于類模板中的模板構造函數 - 如何為第二個參數顯式指定模板參數?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 不能)

                  <legend id='G04aa'><style id='G04aa'><dir id='G04aa'><q id='G04aa'></q></dir></style></legend>
                    • <bdo id='G04aa'></bdo><ul id='G04aa'></ul>
                        <tbody id='G04aa'></tbody>
                    • <tfoot id='G04aa'></tfoot>

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

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

                            主站蜘蛛池模板: 国产精品国产 | 中文字幕日韩欧美一区二区三区 | www久| 久久毛片网站 | 欧美 中文字幕 | 97色免费视频 | 国产伊人久久久 | 国产精品久久久久久久久久久久久久 | 久久9久| 中文字幕免费 | 婷婷久久久久 | 色姑娘综合网 | 久久久久久亚洲精品 | 密室大逃脱第六季大神版在线观看 | 一区精品国产欧美在线 | 在线成人免费视频 | 欧美一区二区三区大片 | 日本精品一区 | 爱爱视频在线观看 | 瑞克和莫蒂第五季在线观看 | 中文精品一区二区 | www国产亚洲精品 | 国产在线精品一区二区 | 久久这里只有精品首页 | 久久久久国产精品一区二区 | 亚洲欧美一区二区三区国产精品 | 中文字幕视频在线 | 欧美视频三级 | a精品视频| 在线视频99| 狠狠干综合视频 | 91精品国产91久久久久久 | 91资源在线 | 精品一区二区三区在线观看国产 | 久久之精品 | 欧美极品少妇xxxxⅹ免费视频 | 黄色网毛片 | 欧美午夜影院 | 精品亚洲一区二区 | 色爱综合网 | 91成人午夜性a一级毛片 |