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

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

        <bdo id='uvCce'></bdo><ul id='uvCce'></ul>
      <tfoot id='uvCce'></tfoot>

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

      C++中通過(guò)指針捕獲異常

      catch exception by pointer in C++(C++中通過(guò)指針捕獲異常)
    2. <legend id='I2V0U'><style id='I2V0U'><dir id='I2V0U'><q id='I2V0U'></q></dir></style></legend>

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

          • <bdo id='I2V0U'></bdo><ul id='I2V0U'></ul>

              <tbody id='I2V0U'></tbody>
                <tfoot id='I2V0U'></tfoot>
                <i id='I2V0U'><tr id='I2V0U'><dt id='I2V0U'><q id='I2V0U'><span id='I2V0U'><b id='I2V0U'><form id='I2V0U'><ins id='I2V0U'></ins><ul id='I2V0U'></ul><sub id='I2V0U'></sub></form><legend id='I2V0U'></legend><bdo id='I2V0U'><pre id='I2V0U'><center id='I2V0U'></center></pre></bdo></b><th id='I2V0U'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='I2V0U'><tfoot id='I2V0U'></tfoot><dl id='I2V0U'><fieldset id='I2V0U'></fieldset></dl></div>
              • 本文介紹了C++中通過(guò)指針捕獲異常的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                我發(fā)現(xiàn)有3種方法可以捕獲異常,有什么區(qū)別?

                I found that there are three ways to catch an exception, what are the differences?

                1) 按值捕獲;

                2) 按引用捕獲;

                3) 通過(guò)指針捕捉;

                我只知道按值捕獲會(huì)調(diào)用對(duì)象的兩個(gè)副本,按引用捕獲會(huì)調(diào)用一個(gè).那么如何通過(guò)指針捕獲呢?什么時(shí)候用指針捕捉?除了拋出一個(gè)對(duì)象,我還能像這樣拋出一個(gè)指向?qū)ο蟮闹羔槅?

                I only know that catch by value will invoke two copies of the object, catch by reference will invoke one. So how about catch by pointer? When to use catch by pointer? In addition to throw an object, can I throw a pointer to an object like this?

                class A {}
                
                void f() {
                
                  A *p = new A();
                        throw p;
                
                
                }
                

                推薦答案

                推薦的方式是按值拋出,按引用捕獲.

                您的示例代碼拋出一個(gè)指針,這是一個(gè)壞主意,因?yàn)槟仨氃诓东@站點(diǎn)管理內(nèi)存.

                Your example code throws a pointer, which is a bad idea since you would have to manage memory at the catch site.

                如果你真的覺(jué)得你應(yīng)該拋出一個(gè)指針,使用智能指針,比如 shared_ptr.

                If you really feel you should throw a pointer, use a smart pointer such as shared_ptr.

                無(wú)論如何,Herb Sutter 和 Alexei Alexandrescu 在我轉(zhuǎn)述的他們的 C++ 編碼標(biāo)準(zhǔn)一書(shū)中很好地解釋了這一點(diǎn).

                請(qǐng)參閱 C++ 編碼標(biāo)準(zhǔn):按值拋出,按引用捕獲.

                這篇關(guān)于C++中通過(guò)指針捕獲異常的文章就介紹到這了,希望我們推薦的答案對(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)文檔推薦

                In what ways do C++ exceptions slow down code when there are no exceptions thown?(當(dāng)沒(méi)有異常時(shí),C++ 異常會(huì)以何種方式減慢代碼速度?)
                Why catch an exception as reference-to-const?(為什么要捕獲異常作為對(duì) const 的引用?)
                When and how should I use exception handling?(我應(yīng)該何時(shí)以及如何使用異常處理?)
                Scope of exception object in C++(C++中異常對(duì)象的范圍)
                Catching exceptions from a constructor#39;s initializer list(從構(gòu)造函數(shù)的初始化列表中捕獲異常)
                Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說(shuō)明符 C++11 noexcept 之間的區(qū)別)

                  <tfoot id='qJHYz'></tfoot>
                1. <legend id='qJHYz'><style id='qJHYz'><dir id='qJHYz'><q id='qJHYz'></q></dir></style></legend>
                    • <bdo id='qJHYz'></bdo><ul id='qJHYz'></ul>

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

                        <tbody id='qJHYz'></tbody>

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

                          主站蜘蛛池模板: 久久国产精品亚洲 | www.国产一区 | 99色综合| a级片网站| 免费观看黄网站 | 欧美日韩国产一区二区三区 | www.亚洲一区 | 日韩视频一区在线观看 | 成人夜晚看av | 精品国产女人 | 在线免费观看黄a | 毛片久久久 | 97精品超碰一区二区三区 | 亚洲成人黄色 | 久久久久久亚洲欧洲 | 欧美日韩在线成人 | 奇米久久久 | 欧美日韩一区二区三区四区 | 日韩免费视频 | 国产一区二区在线免费观看 | 欧美日韩理论 | 99热首页| 好姑娘高清在线观看电影 | 国产一在线 | 午夜免费观看 | 午夜丰满寂寞少妇精品 | 欧美在线a| 狠狠躁18三区二区一区 | 正在播放一区二区 | 日本小视频网站 | 一区二区三| av午夜激情 | yeyeav| 久草免费在线视频 | 99pao成人国产永久免费视频 | 亚洲成人免费视频在线 | 免费视频一区 | 欧美日韩一 | 久久6视频 | 国产伦精品一区二区三区高清 | 欧美精品欧美精品系列 |