久久久久久久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>

        使用模板訪問(wèn) C++ 中超類的受保護(hù)成員

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

          • <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>
                  本文介紹了使用模板訪問(wèn) C++ 中超類的受保護(hù)成員的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

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

                  為什么 C++ 編譯器不能識(shí)別 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
                    }
                  };
                  

                  如果我簡(jiǎn)化 Subclass 并且只是從 Subclass 繼承然后它編譯.當(dāng)將 g() 完全限定為 Superclass::g()Superclass::b 時(shí),它也會(huì)編譯.我使用的是 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.

                  注意:如果我在超類中公開(kāi) g()b ,它仍然會(huì)失敗并出現(xiàn)相同的錯(cuò)誤.

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

                  推薦答案

                  這可以通過(guò)使用 using 將名稱拉入當(dāng)前范圍來(lái)修改:

                  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;
                    }
                  };
                  

                  或者通過(guò)this指針訪問(wèn)來(lái)限定名稱:

                  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;
                    }
                  };
                  

                  或者,正如您已經(jīng)注意到的,通過(guò)限定全名.

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

                  之所以有必要這樣做,是因?yàn)?C++ 不考慮用于名稱解析的超類模板(因?yàn)樗鼈兪菑膶倜Q并且不考慮從屬名稱).它在您使用 Superclass 時(shí)有效,因?yàn)樗皇悄0?它是模板的實(shí)例化),因此它的嵌套名稱不依賴 名字.

                  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.

                  這篇關(guān)于使用模板訪問(wèn) C++ 中超類的受保護(hù)成員的文章就介紹到這了,希望我們推薦的答案對(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 不能)
                    <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. 主站蜘蛛池模板: 亚洲视频一区二区三区 | 一区久久 | 五月激情综合网 | 免费毛片在线播放免费 | 国产天堂在线 | 亚洲男人的天堂在线观看 | 国产无遮挡又黄又爽又色 | 欧美视频精品 | 国产黄色片网站 | 亚洲欧美日韩一区 | 日韩一二区 | 一个色综合网 | 在线观看小视频 | 一区二区三区四区视频 | 国产一区二区三区在线观看视频 | 亚洲国产精品久久久久久久 | 秋霞午夜鲁丝一区二区老狼 | 久久精品www人人爽人人 | 久久久久久亚洲精品 | 亚洲综合激情网 | 91精品国产乱码久久久久久 | av在线精品 | 一区二区亚洲 | 日韩精品久久久久久免费 | 日韩在线中文字幕 | 三级在线播放 | 欧美久久一区二区 | 偷拍福利视频 | 欧美日韩精品一区二区 | 国产九九热| av黄色在线 | 夜夜贪欢〈高h〉 | 精品人伦一区二区三区 | 在线看片a | 日韩视频免费看 | 天天久久综合 | 日韩一区二区三区视频 | 久草综合在线 | 欧美精品入口蜜桃 | 国产中文在线观看 | www.com国产|