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

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

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

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

        在函數(shù)模板特化中覆蓋返回類型

        Overriding return type in function template specialization(在函數(shù)模板特化中覆蓋返回類型)
          <bdo id='nLTyZ'></bdo><ul id='nLTyZ'></ul>

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

            <tbody id='nLTyZ'></tbody>

        • <tfoot id='nLTyZ'></tfoot><legend id='nLTyZ'><style id='nLTyZ'><dir id='nLTyZ'><q id='nLTyZ'></q></dir></style></legend>

                  本文介紹了在函數(shù)模板特化中覆蓋返回類型的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

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

                  我想專門化一個(gè)函數(shù)模板,以便返回類型根據(jù)模板參數(shù)的類型而變化.

                  I would like to specialize a function template such that the return type changes depending on the type of the template argument.

                  class ReturnTypeSpecialization
                  {
                  public:
                      template<typename T>
                      T Item();
                  };
                  
                  // Normally just return the template type
                  template<typename T>
                  T ReturnTypeSpecialization::Item() { ... }
                  
                  // When a float is specified, return an int
                  // This doesn't work:
                  template<float>
                  int ReturnTypeSpecialization::Item() { ... }
                  

                  這可能嗎?我不能使用 C++11.

                  Is this possible? I can't use C++11.

                  推薦答案

                  由于專業(yè)化必須與返回類型的基本模板一致,您可以通過添加返回類型特征"來實(shí)現(xiàn),您可以使用一個(gè)結(jié)構(gòu)專門化并從以下位置繪制真正的返回類型:

                  Since the specialization has to agree with the base template on the return type, you can make it so by adding a "return type trait", a struct you can specialize and draw the true return type from:

                  // in the normal case, just the identity
                  template<class T>
                  struct item_return{ typedef T type; };
                  
                  template<class T>
                  typename item_return<T>::type item();
                  
                  template<>
                  struct item_return<float>{ typedef int type; };
                  template<>
                  int item<float>();
                  

                  現(xiàn)場示例.

                  請注意,您可能希望遵循以下規(guī)則,因此您只需更新 item_return 專業(yè)化中的 return-type.

                  Note that you might want to stick to the following, so you only need to update the return-type in the item_return specialization.

                  template<>
                  item_return<float>::type foo<float>(){ ... }
                  // note: No `typename` needed, because `float` is not a dependent type
                  

                  這篇關(guān)于在函數(shù)模板特化中覆蓋返回類型的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 不能)
                  <legend id='pgDzg'><style id='pgDzg'><dir id='pgDzg'><q id='pgDzg'></q></dir></style></legend>

                  • <small id='pgDzg'></small><noframes id='pgDzg'>

                      <tbody id='pgDzg'></tbody>

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

                          1. 主站蜘蛛池模板: 手机av免费 | 欧美一区二区在线视频 | 一级免费片 | 成人羞羞网站 | 日韩精品三级 | 红桃av在线 | 一级黄色片网站 | 欧美视频在线观看免费 | 午夜影院黄 | 久久新视频| 欧美在线一区二区 | 欧美一级视频 | 国产黄色在线观看 | 一区二区三区视频在线观看 | 成人福利 | 亚洲激情综合 | a天堂在线视频 | 日韩视频免费看 | 亚洲性视频 | 国产精品久久久久久无人区 | 91中文字幕在线 | 天堂成人av| 亚洲精品乱码久久久久久 | 一区二区三区国产 | 999久久久精品 | 黄色成人在线视频 | 欧美视频在线观看 | 99精品色 | 亚洲第一黄网 | 国产一级免费视频 | 黄大色黄大片女爽一次 | 精品国产乱码一区二区三 | 91美女片黄在线观看91美女 | 狠狠做深爱婷婷久久综合一区 | 亚洲美女毛片 | 九九视频在线观看 | 久久精品区 | 欧美极品一区 | 午夜天堂在线 | 亚洲午夜18毛片在线看 | 激情五月综合 |