久久久久久久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ù)模板特化中覆蓋返回類型的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  限時(shí)送ChatGPT賬號(hào)..

                  我想專門化一個(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è)化必須與返回類型的基本模板一致,您可以通過(guò)添加返回類型特征"來(lái)實(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)場(chǎng)示例.

                  請(qǐng)注意,您可能希望遵循以下規(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ù)模板特化中覆蓋返回類型的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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)庫(kù))
                  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网站在线观看 | 国产欧美视频一区 | 一区二区三区视频在线观看 | 91私密视频| 精品久久电影 | 一区二区免费 | 国产精品久久亚洲7777 | 天堂资源最新在线 | 欧美精品一区二区三区在线播放 | 欧美日韩一区二区视频在线观看 | 日韩电影中文字幕 | 久久精品性视频 | 欧美精品一 | 成人激情视频在线观看 | 自拍视频网站 | 福利一区二区 | 懂色中文一区二区在线播放 | 欧美成人精品 | 国产玖玖| 亚洲精品9999 | 四虎成人在线播放 | 亚洲人成人一区二区在线观看 | 激情五月综合 | 天天干天天操天天看 | 免费一区二区 | 天天搞天天搞 | 成人在线影视 | 国产精品久久久久久吹潮日韩动画 | 久久成人国产精品 | 午夜成人免费视频 | 欧美极品在线 | 日韩视频在线一区 | 91精品久久久 | 国产精品视频免费播放 | 国产乱码精品1区2区3区 |