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

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

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

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

        使用模板訪問 C++ 中超類的受保護成員

        accessing protected members of superclass in C++ with templates(使用模板訪問 C++ 中超類的受保護成員)

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

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

                  <tfoot id='WDvYl'></tfoot>
                  本文介紹了使用模板訪問 C++ 中超類的受保護成員的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  為什么 C++ 編譯器不能識別 g()bSuperclass 的繼承成員,如以下代碼所示:

                  Why can't a C++ compiler recognize that g() and b are inherited members of Superclass as seen in this code:

                  template<typename T> struct Superclass {
                   protected:
                    int b;
                    void g() {}
                  };
                  
                  template<typename T> struct Subclass : public Superclass<T> {
                    void f() {
                      g(); // compiler error: uncategorized
                      b = 3; // compiler error: unrecognized
                    }
                  };
                  

                  如果我簡化 Subclass 并且只是從 Subclass 繼承然后它編譯.當將 g() 完全限定為 Superclass::g()Superclass::b 時,它也會編譯.我使用的是 LLVM GCC 4.2.

                  If I simplify Subclass and just inherit from Subclass<int> then it compiles. It also compiles when fully qualifying g() as Superclass<T>::g() and Superclass<T>::b. I'm using LLVM GCC 4.2.

                  注意:如果我在超類中公開 g()b ,它仍然會失敗并出現相同的錯誤.

                  Note: If I make g() and b public in the superclass it still fails with same error.

                  推薦答案

                  這可以通過使用 using 將名稱拉入當前范圍來修改:

                  This can be amended by pulling the names into the current scope using using:

                  template<typename T> struct Subclass : public Superclass<T> {
                    using Superclass<T>::b;
                    using Superclass<T>::g;
                  
                    void f() {
                      g();
                      b = 3;
                    }
                  };
                  

                  或者通過this指針訪問來限定名稱:

                  Or by qualifying the name via the this pointer access:

                  template<typename T> struct Subclass : public Superclass<T> {
                    void f() {
                      this->g();
                      this->b = 3;
                    }
                  };
                  

                  或者,正如您已經注意到的,通過限定全名.

                  Or, as you’ve already noticed, by qualifying the full name.

                  之所以有必要這樣做,是因為 C++ 不考慮用于名稱解析的超類模板(因為它們是從屬名稱并且不考慮從屬名稱).它在您使用 Superclass 時有效,因為它不是模板(它是模板的實例化),因此它的嵌套名稱不依賴 名字.

                  The reason why this is necessary is that C++ doesn’t consider superclass templates for name resolution (because then they are dependent names and dependent names are not considered). It works when you use Superclass<int> because that’s not a template (it’s an instantiation of a template) and thus its nested names are not dependent names.

                  這篇關于使用模板訪問 C++ 中超類的受保護成員的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 不能)
                    <tbody id='8UEZj'></tbody>

                  <small id='8UEZj'></small><noframes id='8UEZj'>

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

                        <tfoot id='8UEZj'></tfoot>

                          1. <legend id='8UEZj'><style id='8UEZj'><dir id='8UEZj'><q id='8UEZj'></q></dir></style></legend>
                          2. 主站蜘蛛池模板: 麻豆成人在线视频 | 国产资源一区二区三区 | 亚洲精品国产一区 | 久久综合久 | 国产电影一区二区 | 日韩欧美一区二区三区在线播放 | 亚洲福利网站 | 97视频精品 | 久久亚洲天堂 | 91精品国产一区二区三区 | 久久久99精品免费观看 | caoporn国产精品免费公开 | 日日干天天干 | 91国自视频 | 亚洲福利精品 | 日韩av大片免费看 | 欧美三区在线观看 | 91九色porny首页最多播放 | 亚洲一区欧美 | 人人射人人 | 操久久 | 成人av在线播放 | 国产精品一区二区久久久久 | 国产伦精品 | 国产高清视频一区二区 | 亚洲在线 | av一区二区在线观看 | 亚洲国产精品一区二区第一页 | 亚洲喷水| 亚洲91精品 | hdfreexxxx中国妞 | 一级黄色影片在线观看 | 午夜免费在线观看 | 精品美女视频在线观看免费软件 | 成人午夜网站 | 欧美理伦片在线播放 | 亚洲精品一区二区三区在线 | 国产日韩欧美 | 国产99视频精品免视看9 | 欧美1级 | 激情综合五月 |