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

<legend id='8a26v'><style id='8a26v'><dir id='8a26v'><q id='8a26v'></q></dir></style></legend>
  • <i id='8a26v'><tr id='8a26v'><dt id='8a26v'><q id='8a26v'><span id='8a26v'><b id='8a26v'><form id='8a26v'><ins id='8a26v'></ins><ul id='8a26v'></ul><sub id='8a26v'></sub></form><legend id='8a26v'></legend><bdo id='8a26v'><pre id='8a26v'><center id='8a26v'></center></pre></bdo></b><th id='8a26v'></th></span></q></dt></tr></i><div class="rrtjxfd" id='8a26v'><tfoot id='8a26v'></tfoot><dl id='8a26v'><fieldset id='8a26v'></fieldset></dl></div>
        <bdo id='8a26v'></bdo><ul id='8a26v'></ul>
      1. <small id='8a26v'></small><noframes id='8a26v'>

      2. <tfoot id='8a26v'></tfoot>

        專用模板類的靜態成員初始化

        static member initialization for specialized template class(專用模板類的靜態成員初始化)
      3. <i id='HY9Pe'><tr id='HY9Pe'><dt id='HY9Pe'><q id='HY9Pe'><span id='HY9Pe'><b id='HY9Pe'><form id='HY9Pe'><ins id='HY9Pe'></ins><ul id='HY9Pe'></ul><sub id='HY9Pe'></sub></form><legend id='HY9Pe'></legend><bdo id='HY9Pe'><pre id='HY9Pe'><center id='HY9Pe'></center></pre></bdo></b><th id='HY9Pe'></th></span></q></dt></tr></i><div class="dxdtp7b" id='HY9Pe'><tfoot id='HY9Pe'></tfoot><dl id='HY9Pe'><fieldset id='HY9Pe'></fieldset></dl></div>
          • <bdo id='HY9Pe'></bdo><ul id='HY9Pe'></ul>

              <tfoot id='HY9Pe'></tfoot>

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

            1. <legend id='HY9Pe'><style id='HY9Pe'><dir id='HY9Pe'><q id='HY9Pe'></q></dir></style></legend>

                    <tbody id='HY9Pe'></tbody>
                  本文介紹了專用模板類的靜態成員初始化的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..
                  class A
                  {
                  };
                  
                  template <typename A, int S>
                  class B
                  {
                  public:
                          static int a[S];
                  
                          B()
                          {
                                  a[0] = 0;
                          }
                  };
                  
                  template<> int B<A, 1>::a[1];
                  
                  int main()
                  {
                          B<A, 1> t;
                          t;
                  }
                  

                  它在 GCC 4.1 下編譯,但不鏈接:

                  It compiles under GCC 4.1, but does not link:

                  static.cpp:(.text._ZN1BI1ALi1EEC1Ev[B<A, 1>::B()]+0x5): undefined reference to `B<A, 1>::a'
                  

                  如果可能的話,我更愿意保持專門的初始化,因為數組保存了一些特定于類型的數據.

                  I would prefer to keep initialisation specialised if it is possible, since the array holds some data specific to the type.

                  推薦答案

                  對于靜態成員特化,如果不初始化成員,則視為特化聲明,只說哦,不要從主模板實例化成員,因為在其他地方有專門的定義".需要說明的是,定義應該出現在.cpp文件中(否則,你會得到相反的結果:多個定義),沒有初始化器的聲明仍然應該放在頭文件中.

                  For static member specializations, if you don't initialize the member, it is taken as a specialization declaration, that just says "Oh, don't instantiate the member from the primary template, because there is a specialized definition somewhere else". It should be mentioned that the definition should appear in a .cpp file (otherwise, you will earn the opposite: multiple definitions), and the declaration without initializer should still be placed in the header file.

                  現在正確的語法確實如下,它應該出現在頭文件中,而是出現在.cpp文件中

                  Now the correct syntax is indeed the following, and it should not appear in a header file, but in a .cpp file

                  template<> int B<A, 1>::a[1] = { };
                  

                  以下內容仍應出現在頭文件中:

                  The following should still appear in a header file:

                  template<> int B<A, 1>::a[1];
                  

                  這將作為專業化聲明.

                  由此可知,您不能特化一個只有默認構造函數且不可復制的成員,因為您需要以下語法:

                  From this, it follows that you can't specialize a member that only has a default constructor and is not copyable, because you would need this syntax:

                  // needs a copy constructor!
                  template<> Type Class<Arguments>::member = Type();
                  

                  C++0x 修復了這個:

                  C++0x fixes this:

                  // doesn't anymore need a copy constructor
                  template<> Type Class<Arguments>::member{};
                  

                  <小時>

                  對于我們當中的標準人來說,這里是引述:


                  For the Standardese people among us, here are the quotes:

                  14.7.3/6:

                  如果模板、成員模板或類模板的成員是顯式特化的,則應在第一次使用該特化之前聲明該特化,這將導致隱式實例化發生,在每個翻譯單元中,使用發生;不需要診斷.

                  If a template, a member template or the member of a class template is explicitly specialized then that specialization shall be declared before the first use of that specialization that would cause an implicit instantiation to take place, in every translation unit in which such a use occurs; no diagnostic is required.

                  14.7.3/15:

                  如果聲明包含初始化程序,則模板的靜態數據成員的顯式特化是定義;否則,它是一個聲明.[注意:需要默認初始化的模板的靜態數據成員的定義沒有語法.

                  An explicit specialization of a static data member of a template is a definition if the declaration includes an initializer; otherwise, it is a declaration. [Note: there is no syntax for the definition of a static data member of a template that requires default initialization.

                  template<> X Q<int>::x;
                  

                  這是一個聲明,不管 X 是否可以默認初始化(8.5).]

                  This is a declaration regardless of whether X can be default initialized (8.5). ]

                  3.2/3:

                  每個程序都應包含該程序中使用的每個非內聯函數或對象的一個??定義;無需診斷.

                  Every program shall contain exactly one definition of every non-inline function or object that is used in that program; no diagnostic required.

                  3.2/5:

                  一個類類型(第 9 條)、枚舉類型(7.2)、具有外部鏈接的內聯函數(7.1.2)、類模板(第 14 條)、非靜態函數模板(14.5)可以有多個定義.5)、類模板的靜態數據成員 (14.5.1.3)、類模板的成員函數 (14.5.1.1) 或在程序中未指定某些模板參數的模板特化 (14.7, 14.5.4)[...]

                  There can be more than one definition of a class type (clause 9), enumeration type (7.2), inline function with external linkage (7.1.2), class template (clause 14), non-static function template (14.5.5), static data member of a class template (14.5.1.3), member function of a class template (14.5.1.1), or template specialization for which some template parameters are not specified (14.7, 14.5.4) in a program [...]

                  將此限制為未指定某些模板參數"意味著我們可以執行以下操作,將其放入標題中(因此可能具有此專業化的多個定義):

                  The restriction of this to "for which some template parameters are not specified" means that we are allowed to do the following, placing it into a header (thus possibly having multiple definitions of this specialization):

                  template<> template<typename T>
                  Type OuterClass<int>::InnerClass<T>::StaticMember = 0;
                  

                  在您的情況下,您已經指定了所有參數,因此它不受允許多個定義的單一定義規則的約束.

                  In your case, you have all parameters specified, making it not being covered by the one defintion rule for allowing multiple definitions.

                  這篇關于專用模板類的靜態成員初始化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 不能)
                  <tfoot id='4h0oD'></tfoot>

                        • <bdo id='4h0oD'></bdo><ul id='4h0oD'></ul>

                          <small id='4h0oD'></small><noframes id='4h0oD'>

                          <i id='4h0oD'><tr id='4h0oD'><dt id='4h0oD'><q id='4h0oD'><span id='4h0oD'><b id='4h0oD'><form id='4h0oD'><ins id='4h0oD'></ins><ul id='4h0oD'></ul><sub id='4h0oD'></sub></form><legend id='4h0oD'></legend><bdo id='4h0oD'><pre id='4h0oD'><center id='4h0oD'></center></pre></bdo></b><th id='4h0oD'></th></span></q></dt></tr></i><div class="fjfznjl" id='4h0oD'><tfoot id='4h0oD'></tfoot><dl id='4h0oD'><fieldset id='4h0oD'></fieldset></dl></div>
                        • <legend id='4h0oD'><style id='4h0oD'><dir id='4h0oD'><q id='4h0oD'></q></dir></style></legend>
                            <tbody id='4h0oD'></tbody>

                            主站蜘蛛池模板: 金属抛光机-磁悬浮抛光机-磁力研磨机-磁力清洗机 - 苏州冠古科技 | 自动焊锡机_点胶机_螺丝机-锐驰机器人 | 福州仿石漆加盟_福建仿石漆厂家-外墙仿石漆加盟推荐铁壁金钢(福建)新材料科技有限公司有保障 | 山东螺杆空压机,烟台空压机,烟台开山空压机-烟台开山机电设备有限公司 | 涂层测厚仪_漆膜仪_光学透过率仪_十大创新厂家-果欧电子科技公司 | 杭州月嫂技术培训服务公司-催乳师培训中心报名费用-产后康复师培训机构-杭州优贝姆健康管理有限公司 | 西门子代理商_西门子变频器总代理-翰粤百科 | 闭端端子|弹簧螺式接线头|防水接线头|插线式接线头|端子台|电源线扣+护线套|印刷电路板型端子台|金笔电子代理商-上海拓胜电气有限公司 | 沧州友城管业有限公司-内外涂塑钢管-大口径螺旋钢管-涂塑螺旋管-保温钢管生产厂家 | 罗茨真空机组,立式无油往复真空泵,2BV水环真空泵-力侨真空科技 | 磁力链接搜索神器_BT磁力狗_CILIMAO磁力猫_高效磁力搜索引擎2024 | 青岛成人高考_山东成考报名网 | 解放卡车|出口|济南重汽|报价大全|山东三维商贸有限公司 | 首页_欧瑞传动官方网站--主营变频器、伺服系统、新能源、软起动器、PLC、HMI | 北京开业庆典策划-年会活动策划公司-舞龙舞狮团大鼓表演-北京盛乾龙狮鼓乐礼仪庆典策划公司 | 根系分析仪,大米外观品质检测仪,考种仪,藻类鉴定计数仪,叶面积仪,菌落计数仪,抑菌圈测量仪,抗生素效价测定仪,植物表型仪,冠层分析仪-杭州万深检测仪器网 | 西安展台设计搭建_西安活动策划公司_西安会议会场布置_西安展厅设计西安旭阳展览展示 | 长春网站建设,五合一网站设计制作,免费优化推广-长春网站建设 | 扬尘在线监测系统_工地噪声扬尘检测仪_扬尘监测系统_贝塔射线扬尘监测设备「风途物联网科技」 | Akribis直线电机_直线模组_力矩电机_直线电机平台|雅科贝思Akribis-杭州摩森机电科技有限公司 | 济南ISO9000认证咨询代理公司,ISO9001认证,CMA实验室认证,ISO/TS16949认证,服务体系认证,资产管理体系认证,SC食品生产许可证- 济南创远企业管理咨询有限公司 郑州电线电缆厂家-防火|低压|低烟无卤电缆-河南明星电缆 | 单级/双级旋片式真空泵厂家,2xz旋片真空泵-浙江台州求精真空泵有限公司 | 河南砖机首页-全自动液压免烧砖机,小型砌块水泥砖机厂家[十年老厂] | 重庆LED显示屏_显示屏安装公司_重庆LED显示屏批发-彩光科技公司 重庆钣金加工厂家首页-专业定做监控电视墙_操作台 | 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库 | 臭氧发生器_臭氧消毒机 - 【同林品牌 实力厂家】 | 双工位钻铣攻牙机-转换工作台钻攻中心-钻铣攻牙机一体机-浙江利硕自动化设备有限公司 | 在线钠离子分析仪-硅酸根离子浓度测定仪-油液水分测定仪价格-北京时代新维测控设备有限公司 | 首页|专注深圳注册公司,代理记账报税,注册商标代理,工商变更,企业400电话等企业一站式服务-慧用心 | 斗式提升机,斗式提升机厂家-淄博宏建机械有限公司 | 高压包-点火器-高压发生器-点火变压器-江苏天网| 硅胶布|电磁炉垫片|特氟龙胶带-江苏浩天复合材料有限公司 | 深圳市源和塑胶电子有限公司-首页 | 耐磨陶瓷,耐磨陶瓷管道_厂家-淄博拓创陶瓷科技 | 网站建设-临朐爱采购-抖音运营-山东兆通网络科技 | 烟气换热器_GGH烟气换热器_空气预热器_高温气气换热器-青岛康景辉 | Q361F全焊接球阀,200X减压稳压阀,ZJHP气动单座调节阀-上海戎钛 | 优秀的临床医学知识库,临床知识库,医疗知识库,满足电子病历四级要求,免费试用 | 洛阳防爆合格证办理-洛阳防爆认证机构-洛阳申请国家防爆合格证-洛阳本安防爆认证代办-洛阳沪南抚防爆电气技术服务有限公司 | 并离网逆变器_高频UPS电源定制_户用储能光伏逆变器厂家-深圳市索克新能源 | 留学生辅导网-在线课程论文辅导-留学生挂科申诉机构 |