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

  • <tfoot id='Sutm6'></tfoot>
      1. <small id='Sutm6'></small><noframes id='Sutm6'>

        <legend id='Sutm6'><style id='Sutm6'><dir id='Sutm6'><q id='Sutm6'></q></dir></style></legend>
          <bdo id='Sutm6'></bdo><ul id='Sutm6'></ul>
        <i id='Sutm6'><tr id='Sutm6'><dt id='Sutm6'><q id='Sutm6'><span id='Sutm6'><b id='Sutm6'><form id='Sutm6'><ins id='Sutm6'></ins><ul id='Sutm6'></ul><sub id='Sutm6'></sub></form><legend id='Sutm6'></legend><bdo id='Sutm6'><pre id='Sutm6'><center id='Sutm6'></center></pre></bdo></b><th id='Sutm6'></th></span></q></dt></tr></i><div class="9zddjf7" id='Sutm6'><tfoot id='Sutm6'></tfoot><dl id='Sutm6'><fieldset id='Sutm6'></fieldset></dl></div>
      2. reinterpret_cast 會導致未定義的行為嗎?

        Does reinterpret_cast lead to undefined behavior?(reinterpret_cast 會導致未定義的行為嗎?)
      3. <legend id='iJYtu'><style id='iJYtu'><dir id='iJYtu'><q id='iJYtu'></q></dir></style></legend>

        1. <i id='iJYtu'><tr id='iJYtu'><dt id='iJYtu'><q id='iJYtu'><span id='iJYtu'><b id='iJYtu'><form id='iJYtu'><ins id='iJYtu'></ins><ul id='iJYtu'></ul><sub id='iJYtu'></sub></form><legend id='iJYtu'></legend><bdo id='iJYtu'><pre id='iJYtu'><center id='iJYtu'></center></pre></bdo></b><th id='iJYtu'></th></span></q></dt></tr></i><div class="39rn7d1" id='iJYtu'><tfoot id='iJYtu'></tfoot><dl id='iJYtu'><fieldset id='iJYtu'></fieldset></dl></div>

            <tbody id='iJYtu'></tbody>
          <tfoot id='iJYtu'></tfoot>

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

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

                  本文介紹了reinterpret_cast 會導致未定義的行為嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我有一個類模板 A,它包含一個指針容器 (T*):

                  I have a class template A which contains a container of pointers (T*):

                  template <typename T>
                  class A {
                  public:
                     // ... 
                  private:
                     std::vector<T*> data;
                  };
                  

                  還有一堆函數,比如:

                  void f(const A<const T>&);
                  void g(const A<const T>&);
                  

                  是否可以通過從 AA 的強制轉換來調用這些函數?

                  Is it OK to call these functions via a cast from A<const T> to A<T>?

                  A<double> a;
                  ... 
                  auto& ac = reinterpret_cast<const A<const double>&>(a);
                  f(ac);
                  

                  我很確定這段代碼有未定義的行為.

                  I'm pretty sure that this code has undefined behaviour.

                  在現實生活中使用此類轉換是否危險?

                  Is it dangerous to use such conversions in real life?

                  推薦答案

                  由于 AA 是不相關的類型,它實際上是未指定的(最初我認為未定義的)行為,相應地,在現實生活中使用它是一個壞主意:你永遠不知道你可以移植什么系統或編譯器來改變行為是奇怪的方式.

                  As A<double> and A<const double> are unrelated types, it's actually unspecified (originally I thought undefined) behavior and correspondingly yes it's a bad idea to use in real life: You never know what system(s) or compiler(s) you may port to that change the behavior is strange ways.

                  參考:

                  5.2.10/11:

                  T1 類型的左值表達式可以轉換為引用到T2",如果指向 T1 的指針"類型的表達式可以顯式表示使用 reinterpret_cast 轉換為指向 T2 的指針"類型.那即,參考強制轉換 reinterpret_cast(x) 具有相同的效果使用內置的 & 轉換 *reinterpret_cast(&x)和 *運算符(與 reinterpret_cast(x) 類似).

                  An lvalue expression of type T1 can be cast to the type "reference to T2" if an expression of type "pointer to T1" can be explicitly converted to the type "pointer to T2" using a reinterpret_cast. That is, a reference cast reinterpret_cast(x) has the same effect as the conversion *reinterpret_cast(&x) with the built-in & and * operators (and similarly for reinterpret_cast(x)).

                  所以他們將我們重定向到了之前的 5.2.10/7 部分:

                  So they've redirected us to an earlier section 5.2.10/7:

                  對象指針可以顯式轉換為一種不同的類型.... ... 轉換類型的純右值指向 T1 的指針"指向指向 T2 的指針"類型(其中 T1 和 T2 是對象類型和 T2 的對齊要求沒有的地方比 T1) 更嚴格并返回到其原始類型產生原始指針值.任何其他此類指針的結果轉換未指定.

                  An object pointer can be explicitly converted to an object pointer of a different type. ... ... Converting a prvalue of type "pointer to T1" to the type "pointer to T2" (where T1 and T2 are object types and where the alignment requirements of T2 are no stricter than those of T1) and back to its original type yields the original pointer value. The result of any other such pointer conversion is unspecified.

                  如果 fg 是適用于容器的算法,那么簡單的解決方案是將它們更改為適用于范圍(迭代器對)的模板算法.

                  If f and g are algorithms that work on containers, the easy solution is to change them to template algorithms that work on ranges (iterator pairs).

                  這篇關于reinterpret_cast 會導致未定義的行為嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 不能)
                  • <small id='v4weN'></small><noframes id='v4weN'>

                      <tfoot id='v4weN'></tfoot>

                    • <legend id='v4weN'><style id='v4weN'><dir id='v4weN'><q id='v4weN'></q></dir></style></legend>
                        1. <i id='v4weN'><tr id='v4weN'><dt id='v4weN'><q id='v4weN'><span id='v4weN'><b id='v4weN'><form id='v4weN'><ins id='v4weN'></ins><ul id='v4weN'></ul><sub id='v4weN'></sub></form><legend id='v4weN'></legend><bdo id='v4weN'><pre id='v4weN'><center id='v4weN'></center></pre></bdo></b><th id='v4weN'></th></span></q></dt></tr></i><div class="8zye3c7" id='v4weN'><tfoot id='v4weN'></tfoot><dl id='v4weN'><fieldset id='v4weN'></fieldset></dl></div>
                            <tbody id='v4weN'></tbody>
                            <bdo id='v4weN'></bdo><ul id='v4weN'></ul>
                            主站蜘蛛池模板: 航空铝型材,7系铝型材挤压,硬质阳*氧化-余润铝制品 | 青岛侦探_青岛侦探事务所_青岛劝退小三_青岛调查出轨取证公司_青岛婚外情取证-青岛探真调查事务所 | 泉州陶瓷pc砖_园林景观砖厂家_石英砖地铺石价格 _福建暴风石英砖 | 基业箱_环网柜_配电柜厂家_开关柜厂家_开关断路器-东莞基业电气设备有限公司 | 室内室外厚型|超薄型|非膨胀型钢结构防火涂料_隧道专用防火涂料厂家|电话|价格|批发|施工 | 诚暄电子公司首页-线路板打样,pcb线路板打样加工制作厂家 | 温州在线网| 东莞螺杆空压机_永磁变频空压机_节能空压机_空压机工厂批发_深圳螺杆空压机_广州螺杆空压机_东莞空压机_空压机批发_东莞空压机工厂批发_东莞市文颖设备科技有限公司 | 紫外荧光硫分析仪-硫含量分析仪-红外光度测定仪-泰州美旭仪器 | 福建成考网-福建成人高考网| wika威卡压力表-wika压力变送器-德国wika代理-威卡总代-北京博朗宁科技 | 头条搜索极速版下载安装免费新版,头条搜索极速版邀请码怎么填写? - 欧远全 | 彭世修脚_修脚加盟_彭世修脚加盟_彭世足疗加盟_足疗加盟连锁_彭世修脚技术培训_彭世足疗 | 冷凝锅炉_燃气锅炉_工业燃气锅炉改造厂家-北京科诺锅炉 | 网站建设,北京网站建设,北京网站建设公司,网站系统开发,北京网站制作公司,响应式网站,做网站公司,海淀做网站,朝阳做网站,昌平做网站,建站公司 | 佛山市德信昌电子有限公司 | 珠海网站建设_响应网站建设_珠海建站公司_珠海网站设计与制作_珠海网讯互联 | 烟气换热器_GGH烟气换热器_空气预热器_高温气气换热器-青岛康景辉 | 淄博不锈钢无缝管,淄博不锈钢管-鑫门物资有限公司 | 杜甫仪器官网|实验室平行反应器|升降水浴锅|台式低温循环泵 | 碎石机设备-欧版反击破-欧版颚式破碎机(站)厂家_山东奥凯诺机械 高低温试验箱-模拟高低温试验箱订制-北京普桑达仪器科技有限公司【官网】 | 361°官方网站 | 杭州火蝠电商_京东代运营_拼多多全托管代运营【天猫代运营】 | 智慧农业|农业物联网|现代农业物联网-托普云农物联网官方网站 | 烽火安全网_加密软件、神盾软件官网| 小港信息港-鹤壁信息港 鹤壁老百姓便民生活信息网站 | 锥形螺带干燥机(新型耙式干燥机)百科-常州丰能干燥工程 | 北京律师咨询_知名专业北京律师事务所_免费法律咨询 | 对夹式止回阀_对夹式蝶形止回阀_对夹式软密封止回阀_超薄型止回阀_不锈钢底阀-温州上炬阀门科技有限公司 | 保镖公司-私人保镖-深圳保镖公司【环宇兄弟保镖】 | 磁力轮,磁力联轴器,磁齿轮,钕铁硼磁铁-北京磁运达厂家 | 衬四氟_衬氟储罐_四氟储罐-无锡市氟瑞特防腐科技有限公司 | 电动葫芦|防爆钢丝绳电动葫芦|手拉葫芦-保定大力起重葫芦有限公司 | 日本东丽膜_反渗透膜_RO膜价格_超滤膜_纳滤膜-北京东丽阳光官网 日本细胞免疫疗法_肿瘤免疫治疗_NK细胞疗法 - 免疫密码 | 传动滚筒_厂家-淄博海恒机械制造厂 | 衬塑设备,衬四氟设备,衬氟设备-淄博鲲鹏防腐设备有限公司 | 袋式过滤器,自清洗过滤器,保安过滤器,篮式过滤器,气体过滤器,全自动过滤器,反冲洗过滤器,管道过滤器,无锡驰业环保科技有限公司 | 不锈钢酒柜|恒温酒柜|酒柜定制|酒窖定制-上海啸瑞实业有限公司 | 宏源科技-房地产售楼系统|线上开盘系统|售楼管理系统|线上开盘软件 | 无负压供水设备,消防稳压供水设备-淄博创辉供水设备有限公司 | 广州冷却塔维修厂家_冷却塔修理_凉水塔风机电机填料抢修-广东康明节能空调有限公司 |