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

  • <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="qwawimqqmiuu" 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="qwawimqqmiuu" 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="qwawimqqmiuu" 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>
                            主站蜘蛛池模板: 国产区在线 | 精品久久久久久国产 | 国产精品一区二 | 中文字幕日韩欧美一区二区三区 | 色综合久久88色综合天天 | 人人干人人看 | 免费国产视频 | 视频一区二区国产 | 久久久久九九九女人毛片 | 久久99精品久久久久久国产越南 | 欧美在线一区二区三区 | 国产日韩精品一区二区 | 中文字幕 在线观看 | 久久久精品一区二区三区 | 在线国产视频 | 欧美影院 | 亚洲精品一区二区网址 | 亚洲网站在线播放 | 综合国产| 国产精品1区2区 | 亚洲三区在线观看 | 成人超碰 | 精品亚洲一区二区三区四区五区 | 中文字幕精品一区二区三区精品 | 欧美精品三区 | 热99| 日韩精品色网 | 国产亚洲人成a在线v网站 | 超碰在线播 | 二区在线视频 | 免费在线观看黄色av | 天堂资源 | 91精品欧美久久久久久久 | 老熟女毛片 | h片在线看 | 日韩欧美精品在线 | 九九热视频这里只有精品 | 久国产视频 | 午夜看电影在线观看 | 精品国产精品国产偷麻豆 | 九色国产 |