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

    <legend id='vsbZG'><style id='vsbZG'><dir id='vsbZG'><q id='vsbZG'></q></dir></style></legend>

      <bdo id='vsbZG'></bdo><ul id='vsbZG'></ul>

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

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

      <tfoot id='vsbZG'></tfoot>

    1. 實(shí)例化模板時(shí),其不完整參數(shù)類型的成員是否應(yīng)

      When instantiating a template, should members of its incomplete argument types be visible?(實(shí)例化模板時(shí),其不完整參數(shù)類型的成員是否應(yīng)該可見?)

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

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

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

                  <tbody id='g6Yft'></tbody>
              • 本文介紹了實(shí)例化模板時(shí),其不完整參數(shù)類型的成員是否應(yīng)該可見?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

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

                在下面的例子中,A 有一個(gè)成員 typedef Instantiate,它導(dǎo)致 B 的實(shí)例化.

                In the following example, A has a member typedef Instantiate which causes the instantiation of B<A>.

                template<typename T>
                struct B
                {
                    typedef typename T::Before Before; // ok
                    typedef typename T::After After; // error: no type named 'After' in 'A<int>'
                };
                
                template<typename T>
                struct A
                {
                    typedef int Before;
                    typedef typename B<A>::After Instantiate;
                    typedef int After;
                };
                
                template struct A<int>; // instantiate A<int>
                

                我嘗試過的所有編譯器都報(bào)告說,雖然 A::Before 可見,但 A::After 不可見.這種行為是否符合標(biāo)準(zhǔn)?如果是這樣,標(biāo)準(zhǔn)在哪里指定在 B<A> 的實(shí)例化過程中 A 中的哪些名稱應(yīng)該是可見的?

                All the compilers I've tried report that, while A::Before is visible, A::After is not. Is this behaviour compliant with the standard? If so, where does the standard specify which names in A should be visible during instantiation of B<A>?

                如果依賴名稱是在模板實(shí)例化點(diǎn)查找",那么在名稱由模板參數(shù)(例如 T::After)限定的情況下,這意味著什么?

                If dependent names are "looked up at the point of the template instantiation", what does this mean in the scenario of a name qualified by a template parameter such as T::After?

                請(qǐng)注意,當(dāng) A 不是模板時(shí)會(huì)發(fā)生相同的行為:

                Note that the same behaviour occurs when A is not a template:

                template<typename T>
                struct B
                {
                    typedef typename T::Before Before; // ok
                    typedef typename T::After After; // error: no type named 'After' in 'A'
                };
                
                struct A
                {
                    typedef int Before;
                    typedef B<A>::After Instantiate;
                    typedef int After;
                };
                

                .. 和 G++ 接受以下內(nèi)容,但 Clang 不接受:

                .. and G++ accepts the following, but Clang does not:

                template<typename T>
                struct B
                {
                    static const int value = 0;
                    static const int i = T::value; // clang error: not a constant expression
                };
                
                struct A
                {
                    static const int value = B<A>::value;
                };
                

                在閱讀了 C++03 標(biāo)準(zhǔn)之后:

                After some reading of the C++03 standard:

                [temp.dep.type] 一個(gè)類型是依賴的,如果它是一個(gè)模板參數(shù)

                [temp.dep.type] A type is dependent if it is a template parameter

                因此 T 是依賴的.

                [temp.res] 在查找模板定義中使用的名稱的聲明時(shí),通常的查找規(guī)則用于非依賴名稱.依賴模板參數(shù)的名稱查找被推遲到實(shí)際模板參數(shù)已知.

                [temp.res] When looking for the declaration of a name used in a template definition, the usual lookup rules are used for nondependent names. The lookup of names dependent on the template parameters is postponed until the actual template argument is known.

                T::After 的查找因此被推遲,直到 T 的參數(shù)已知.

                The lookup of T::After is therefore postponed until the argument for T is known.

                [temp.inst] 除非已顯式實(shí)例化類模板特化……當(dāng)在需要完全定義的對(duì)象類型的上下文中引用特化時(shí),類模板特化會(huì)被隱式實(shí)例化.

                [temp.inst] Unless a class template specialization has been explicitly instantiated ... the class template specialization is implicitly instantiated when the specialization is referenced in a context that requires a completely-defined object type.

                因此 A<int>::Instantiate 的聲明需要 B<A> 的實(shí)例化(因?yàn)樗糜谇短酌Q說明符.)

                Therefore the declaration of A<int>::Instantiate requires the instantiation of B<A> (because it is used in a nested-name-specifier.)

                A<int>::AfterA<int>::Instantiate 的聲明點(diǎn)不可見,所以編譯器的行為是有道理的 -但我在 C++03 中沒有看到任何明確描述這種行為的內(nèi)容.最接近的是這個(gè)有點(diǎn)模糊的段落:

                A<int>::After is not visible at the point of declaration of A<int>::Instantiate, so the behaviour of the compiler makes sense - but I haven't seen anything in C++03 that explicitly describes this behaviour. The closest thing was this somewhat vague paragraph:

                [temp.dep.res]在解析依賴名稱時(shí),會(huì)考慮來自以下來源的名稱:

                [temp.dep.res] In resolving dependent names, names from the following sources are considered:

                ——在模板定義點(diǎn)可見的聲明.

                — Declarations that are visible at the point of definition of the template.

                推薦答案

                typename T::Before 是否有效在規(guī)范中沒有明確說明.它是缺陷報(bào)告的主題(因?yàn)榭梢苑浅:侠淼亻喿x標(biāo)準(zhǔn)來禁止它):http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#287.

                Whether typename T::Before is valid is not explicitly said by the spec. It is subject of a defect report (because the Standard can very reasonably be read to forbid it): http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#287 .

                typename T::After 是否無效也可以很合理地被規(guī)范讀取為真的,實(shí)際上它有相當(dāng)多的意義(并且前面提到的 DR 仍然保持格式錯(cuò)誤).因?yàn)槟幸粋€(gè)類 A 的實(shí)例化,它在成員 Baz 具有的期間引用了另一個(gè)類 A尚未聲明,這會(huì)引用回 A<Foo>::Bar.在非模板的情況下,這也是格式錯(cuò)誤的(嘗試暫時(shí)忘記"您正在處理模板:B<A>::After 的查找肯定已完成A 模板被完全解析,但不是在它的具體實(shí)例化完全創(chuàng)建之后.實(shí)際上是它的實(shí)例化做參考!)

                Whether typename T::After is invalid can also very reasonably be read to be true by the spec, and actually it makes quite a bit of sense (and aforementioned DR still keeps it ill-formed). Because you have an instantiation of a class A<Foo>, which references another class A<Bar> during a period where a member Baz has not yet been declared, and that makes a reference back to A<Foo>::Bar. That is ill-formed in the case of non-templates aswell (try to "forget" for a moment that you are dealing with templates: surely the lookup of B<A>::After is done after the A template was completely parsed, but not after the specific instantiation of it was completely created. And it is the instantiation of it that actually will do the reference!).

                struct A {
                   typedef int Foo;
                   typedef A::Foo Bar; // valid
                   typedef A::Baz Lulz; // *not* valid
                   typedef int Baz; 
                };
                

                這篇關(guān)于實(shí)例化模板時(shí),其不完整參數(shù)類型的成員是否應(yīng)該可見?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(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)庫)
                gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數(shù)模板,而 clang 不能)
              • <legend id='xc460'><style id='xc460'><dir id='xc460'><q id='xc460'></q></dir></style></legend>
                    <bdo id='xc460'></bdo><ul id='xc460'></ul>

                        <tbody id='xc460'></tbody>

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

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

                        • 主站蜘蛛池模板: 免费黄色av| 成人aaa| 亚洲一级在线 | 神马香蕉久久 | 亚洲福利专区 | 午夜www | 在线观看一区 | 亚洲欧美日韩一区 | 艳妇臀荡乳欲伦交换h漫 | 不卡在线视频 | 欧美日韩一区二区在线 | 天天干天天操天天摸 | 成人欧美一区二区三区白人 | 日韩欧美一级 | 成人免费在线播放 | 色婷婷网| 91免费在线看 | 欧美午夜在线观看 | 91麻豆精品视频 | 狠狠干在线视频 | 婷婷激情综合 | 中国农村毛片免费播放 | 欧美一区二区三区在线观看 | 男女h黄动漫啪啪无遮挡软件 | 日韩免费一区二区三区 | 成年人免费在线观看 | 日本在线www | 夜夜夜夜操| 黄色录像一级片 | 久久精品黄色 | 在线精品一区 | 国产精品久久久999 成人在线国产 | 91久色| 欧美日韩精品一区 | 亚洲综合激情网 | 精品久久一区二区 | 亚洲欧美另类在线 | 毛片毛片毛片 | 在线观看黄网 | 黄色在线免费观看视频 | 四虎影院最新网址 |