pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<tfoot id='8vOYk'></tfoot>
    <legend id='8vOYk'><style id='8vOYk'><dir id='8vOYk'><q id='8vOYk'></q></dir></style></legend>

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

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

        模板中的類使用不完整

        Incomplete class usage in template(模板中的類使用不完整)
        <legend id='htCQm'><style id='htCQm'><dir id='htCQm'><q id='htCQm'></q></dir></style></legend>
            <tbody id='htCQm'></tbody>

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

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

                • 本文介紹了模板中的類使用不完整的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

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

                  我很驚訝在各種采樣版本的 g++ 上,以下編譯沒(méi)有錯(cuò)誤或警告:

                  I am very surprised that on various sampled versions of g++, the following compiles without error or warning:

                  // Adapted from boost::checked_delete()
                  template <class T> inline void assert_complete()
                  {
                    typedef char type_must_be_complete[ sizeof(T) ? 1 : -1 ];
                    (void) sizeof(type_must_be_complete);
                  }
                  
                  class X;
                  
                  void f()
                  {
                    assert_complete<X>();
                  }
                  
                  class X {};
                  
                  int main() {}
                  

                  如果 X 的定義缺失或在不同的翻譯單元中,我會(huì)得到錯(cuò)誤.

                  If the definition of X is missing or in a different translation unit, I do get errors.

                  但是在上面的程序中,f的定義不是我模板的單個(gè)實(shí)例化點(diǎn)嗎?在那個(gè)實(shí)例化點(diǎn) X 的不完整性難道不是語(yǔ)義錯(cuò)誤嗎?

                  But in the program as above, isn't the definition of f the single instantiation point of my template? And isn't the incompleteness of X at that instantiation point a semantic error?

                  (C++03 和/或 C++11 草案)標(biāo)準(zhǔn)是否稱此程序?yàn)楦袷搅己谩⒏袷藉e(cuò)誤、格式錯(cuò)誤但不需要診斷或未定義的行為?

                  Does the (C++03 and/or C++11 Draft) Standard call this program well-formed, ill-formed, ill-formed but diagnostic not required, or undefined behavior?

                  @David Rodriguez - dribeas 報(bào)告說(shuō),clang++、comeau 和 Visual Studio 2010 也接受類似的代碼.

                  @David Rodriguez - dribeas reports that clang++, comeau, and Visual Studio 2010 also accept similar code.

                  推薦答案

                  (我一直在等 Alf Steinbach 發(fā)布答案,但由于他不這樣做,我將發(fā)布他在 Lounge C++ chat 中提到的參考):

                  (I was waiting to Alf Steinbach to post an answer, but since he is not doing it, I will post the reference that he mentioned in the Lounge C++ chat):

                  標(biāo)準(zhǔn)表明模板實(shí)例化在翻譯單元已經(jīng)翻譯之后執(zhí)行,因此及時(shí),模板實(shí)例化發(fā)生所有非模板化元素已經(jīng)被處理.這在第 2.2 部分翻譯階段中進(jìn)行了描述:

                  The standard indicates that template instantiations are performed after the translation unit has already been translated, so that in time, template instantiations happen after all the non templated elements have already been processed. This is described in section 2.2 Phases of translation:

                  第 1-6 段定義了預(yù)處理器的工作和基本的文本操作(字符集的轉(zhuǎn)換、文字的連接......)

                  Paragraphs 1-6 define the preprocessor work and basic textual operations (conversions of the character set, concatenation of literals...)

                  7/分隔標(biāo)記的空白字符不再重要.每個(gè)預(yù)處理令牌都被轉(zhuǎn)換為一個(gè)令牌.(2.7).生成的標(biāo)記在句法和語(yǔ)義上進(jìn)行分析并作為翻譯單元進(jìn)行翻譯.

                  7/ White-space characters separating tokens are no longer significant. Each preprocessing token is converted into a token. (2.7). The resulting tokens are syntactically and semantically analyzed and translated as a translation unit.

                  8/翻譯的翻譯單元和實(shí)例化單元的組合如下:檢查每個(gè)翻譯的翻譯單元以生成所需實(shí)例化的列表.找到所需模板的定義.是否需要包含這些定義的翻譯單元的源是實(shí)現(xiàn)定義的.執(zhí)行所有必需的實(shí)例化以生成實(shí)例化單元.[ 注意:這些類似于翻譯的翻譯單元,但不包含對(duì)未實(shí)例化模板的引用,也沒(méi)有模板定義.— end note ] 如果任何實(shí)例化失敗,程序就是格式錯(cuò)誤的.

                  8/ Translated translation units and instantiation units are combined as follows: Each translated translation unit is examined to produce a list of required instantiations. The definitions of the required templates are located. It is implementation-defined whether the source of the translation units containing these definitions is required to be available. All the required instantiations are performed to produce instantiation units. [ Note: These are similar to translated translation units, but contain no references to uninstantiated templates and no template definitions. — end note ] The program is ill-formed if any instantiation fails.

                  為簡(jiǎn)潔起見(jiàn),我刪除了一些注釋.現(xiàn)在重要的一點(diǎn)似乎是在一步中轉(zhuǎn)換代碼而不觸發(fā)模板實(shí)例化,然后在后面的步驟中實(shí)例化模板.這反過(guò)來(lái)意味著,如果類型在翻譯單元中的任何位置完整,那么在編譯器進(jìn)行實(shí)例化時(shí)它就會(huì)被處理.

                  I have removed some of the notes for brevity. Now the important bit seems to be that the code is translated without triggering template instantiations in one step, and then in a later step the templates are instantiated. This in turn means that if the type is complete anywhere in the translation unit, it will have been processed by the time the compiler gets to the instantiation.

                  免責(zé)聲明:對(duì)于我嘗試過(guò)的所有編譯器都表現(xiàn)出完全相同的行為(gcc、clang、comeau、VS 2010),這似乎是一個(gè)很好的理由,但這僅說(shuō)明了當(dāng)及時(shí)執(zhí)行實(shí)例化時(shí),它沒(méi)有明確聲明類型在模板實(shí)例化點(diǎn)可能是不完整的.

                  Disclaimer: This seems like a good reason for all of the compilers that I have tried showing the exact same behavior (gcc, clang, comeau, VS 2010), but this only states when in time the instantiation is performed, it does not explicitly state that the type can be incomplete at the point of instantiation of the template.

                  這篇關(guān)于模板中的類使用不完整的文章就介紹到這了,希望我們推薦的答案對(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 不能)

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

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

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

                      1. <tfoot id='Jclvh'></tfoot>
                          • 主站蜘蛛池模板: 叉车电池-叉车电瓶-叉车蓄电池-铅酸蓄电池-电动叉车蓄电池生产厂家 | 科普仪器菏泽市教育教学仪器总厂| 青州搬家公司电话_青州搬家公司哪家好「鸿喜」青州搬家 | 烘箱-工业烘箱-工业电炉-实验室干燥箱 - 苏州华洁烘箱制造有限公司 | 智能垃圾箱|垃圾房|垃圾分类亭|垃圾分类箱专业生产厂家定做-宿迁市传宇环保设备有限公司 | 电伴热系统施工_仪表电伴热保温箱厂家_沃安电伴热管缆工业技术(济南)有限公司 | 鑫铭东办公家具一站式定制采购-深圳办公家具厂家直销 | 长江船运_国内海运_内贸船运_大件海运|运输_船舶运输价格_钢材船运_内河运输_风电甲板船_游艇运输_航运货代电话_上海交航船运 | pbt头梳丝_牙刷丝_尼龙毛刷丝_PP塑料纤维合成毛丝定制厂_广州明旺 | 并网柜,汇流箱,电控设备,中高低压开关柜,电气电力成套设备,PLC控制设备订制厂家,江苏昌伟业新能源科技有限公司 | 仿古建筑设计-仿古建筑施工-仿古建筑公司-汉匠古建筑设计院 | CNC机加工-数控加工-精密零件加工-ISO认证厂家-鑫创盟 | 高精度电阻回路测试仪-回路直流电阻测试仪-武汉特高压电力科技有限公司 | 船用锚链|专业锚链生产厂家|安徽亚太锚链制造有限公司 | 杭州公司变更法人-代理记账收费价格-公司注销代办_杭州福道财务管理咨询有限公司 | 岸电电源-60HZ变频电源-大功率变频电源-济南诚雅电子科技有限公司 | 光栅尺_Magnescale探规_磁栅尺_笔式位移传感器_苏州德美达 | 阀门智能定位器_电液动执行器_气动执行机构-赫尔法流体技术(北京)有限公司 | 自动记录数据电子台秤,记忆储存重量电子桌称,设定时间记录电子秤-昆山巨天 | 武汉高温老化房,恒温恒湿试验箱,冷热冲击试验箱-武汉安德信检测设备有限公司 | 开云(中国)Kaiyun·官方网站-登录入口| 精密模具制造,注塑加工,吹塑和吹瓶加工,EPS泡沫包装生产 - 济南兴田塑胶有限公司 | 同步带轮_同步带_同步轮_iHF合发齿轮厂家-深圳市合发齿轮机械有限公司 | 佛山市钱丰金属不锈钢蜂窝板定制厂家|不锈钢装饰线条|不锈钢屏风| 电梯装饰板|不锈钢蜂窝板不锈钢工艺板材厂家佛山市钱丰金属制品有限公司 | 多功能干燥机,过滤洗涤干燥三合一设备-无锡市张华医药设备有限公司 | 气弹簧定制-气动杆-可控气弹簧-不锈钢阻尼器-工业气弹簧-可调节气弹簧厂家-常州巨腾气弹簧供应商 | 蔬菜清洗机_环速洗菜机_异物去除清洗机_蔬菜清洗机_商用洗菜机 - 环速科技有限公司 | 深圳侦探联系方式_深圳小三调查取证公司_深圳小三分离机构 | 立式硫化罐-劳保用品硫化罐-厂家直销-山东鑫泰鑫硫化罐厂家 | 台式低速离心机-脱泡离心机-菌种摇床-常州市万丰仪器制造有限公司 | 杭州货架订做_组合货架公司_货位式货架_贯通式_重型仓储_工厂货架_货架销售厂家_杭州永诚货架有限公司 | 不锈钢螺丝,不锈钢螺栓,不锈钢标准件-江苏百德特种合金有限公司 交变/复合盐雾试验箱-高低温冲击试验箱_安奈设备产品供应杭州/江苏南京/安徽马鞍山合肥等全国各地 | 土壤养分检测仪|土壤水分|土壤紧实度测定仪|土壤墒情监测系统-土壤仪器网 | 电子巡更系统-巡检管理系统-智能巡检【金万码】 | 油液红外光谱仪-油液监测系统-燃油嗅探仪-上海冉超光电科技有限公司 | 氢氧化钙设备, 氢氧化钙生产线-淄博惠琛工贸有限公司 | T恤衫定做,企业文化衫制作订做,广告T恤POLO衫定制厂家[源头工厂]-【汉诚T恤定制网】 | 蔬菜清洗机_环速洗菜机_异物去除清洗机_蔬菜清洗机_商用洗菜机 - 环速科技有限公司 | 吉祥新世纪铝塑板_生产铝塑板厂家_铝塑板生产厂家_临沂市兴达铝塑装饰材料有限公司 | 安徽千住锡膏_安徽阿尔法锡膏锡条_安徽唯特偶锡膏_卡夫特胶水-芜湖荣亮电子科技有限公司 | 北京自然绿环境科技发展有限公司专业生产【洗车机_加油站洗车机-全自动洗车机】 |