{"id":279886,"date":"2021-01-11T07:43:05","date_gmt":"2021-01-10T23:43:05","guid":{"rendered":"http:\/\/4563.org\/?p=279886"},"modified":"2021-01-11T07:43:05","modified_gmt":"2021-01-10T23:43:05","slug":"%e7%bb%99%e6%96%b0%e6%89%8b-c-developer-%e7%9a%84-tips-1","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=279886","title":{"rendered":"\u7ed9\u65b0\u624b C++ Developer \u7684 Tips 1"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u7ed9\u65b0\u624b C++ Developer \u7684 Tips 1               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dorafmon <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5927\u5bb6\u597d\uff0c\u6211\u53c8\u6765\u5b89\u5229\u6211\u7684\u89c6\u9891\u4e86\uff0c\u56e0\u4e3a\u5728\u5e73\u65f6\u5de5\u4f5c \/\u9762\u8bd5\u7684\u8fc7\u7a0b\u4e2d\u7ecf\u5e38\u4f1a\u9047\u5230\u4e00\u4e9b\u5173\u4e8e C++\u7684\u7ec6\u8282\uff0c\u800c\u8fd9\u4e9b\u77e5\u8bc6\u70b9\u5927\u591a\u6563\u843d\u5728\u5404\u79cd\u4e66 \/\u535a\u5ba2 \/github repo \u91cc\uff0c\u6240\u4ee5\u6211\u60f3\u628a\u8fd9\u4e9b\u77e5\u8bc6\u603b\u7ed3\u6210\u6bcf\u4e2a 10mins \u5de6\u53f3\u7684\u89c6\u9891\uff0c\u5206\u4eab\u7ed9\u5927\u5bb6\uff0c\u4e5f\u662f\u6211\u81ea\u5df1\u5bf9\u81ea\u5df1\u77e5\u8bc6\u56fe\u8c31\u7684\u4e00\u4e2a\u68b3\u7406\u3002\u6211\u5728\u5f55\u8fd9\u4e2a\u89c6\u9891\u7684\u65f6\u5019\u9762\u5bf9\u7684\u5bf9\u8c61\u4eba\u7fa4\u662f junior C++ developer\uff0c\u60f3\u597d\u597d\u51c6\u5907 C++\u77e5\u8bc6\u9762\u8bd5\uff0c\u6216\u8005\u662f\u60f3\u5b66\u4e60\u4e00\u4e9b\u8ddf C++\u6709\u5173\u7684\u80fd\u5e94\u7528\u5728\u5de5\u4f5c\u4e2d\u7684 best practice \u3002\u56e0\u4e3a\u6211\u81ea\u5df1\u5728\u56fd\u5916\uff0c\u6240\u4ee5\u6709\u4e9b\u65f6\u5019\u6709\u4e9b\u4e2d\u82f1\u6df7\u6742\uff0c\u5b9e\u5728\u4e0d\u597d\u610f\u601d\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u7b2c\u4e00\u4e2a\u89c6\u9891\uff0c\u8bb2\u7684\u662f\u5173\u4e8e C++ exception \u7684\u4e00\u4e2a\u5c0f\u77e5\u8bc6\u70b9~<\/p>\n<p>C++\u201c\u535a\u5927\u7cbe\u6df1\u201d\uff0c\u6211\u4e5f\u53ea\u662f\u4e2a\u5c0f\u5b66\u751f\uff0c\u96be\u514d\u4f1a\u51fa\u9519\uff0c\u8fd8\u8bf7\u5927\u5bb6\u65a7\u6b63\u3002<\/p>\n<p>\u4e5f\u70e6\u8bf7\u5927\u5bb6 subscribe \u6211\u7684 youtube \u9891\u9053\uff1a https:\/\/www.youtube.com\/channel\/UCg4d15bORamNqf-fPz9e9aw<\/p>\n<p>\u89c6\u9891\u5730\u5740\uff1a B \u7ad9\uff1a https:\/\/www.bilibili.com\/video\/BV1jf4y1y7gc youtube\uff1a https:\/\/www.youtube.com\/watch?v=T5Z2iFHpoy8<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>8<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4937928\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wutiantong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6ca1\u6709\u7a3f\u5b50\u78d5\u78d5\u7eca\u7eca\u7684\u8bb2\u89e3\u4ee4\u4eba\u96be\u4ee5\u5fcd\u53d7\u3002<br \/>\u53e6\u5916\u6211\u67e5\u4e86\uff0c\u6790\u6784\u51fd\u6570\u662f\u53ef\u4ee5\u629b\u5f02\u5e38\u7684\uff0c\u5373\u4f7f\u5728 stack unwinding \u4e2d\u4e5f\u4e0d\u662f\u672a\u5b9a\u4e49\u884c\u4e3a\uff1a<\/p>\n<p>As any other function, a destructor may terminate by throwing an exception (this usually requires it to be explicitly declared noexcept(false)) (since C++11), however if this destructor happens to be called during stack unwinding, std::terminate is called instead.<br \/>https:\/\/en.cppreference.com\/w\/cpp\/language\/destructor                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4937929\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : dorafmon <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wutiantong \u55ef\u55ef \u4e0b\u56de\u6211\u4e89\u53d6\u5148\u5199\u4e2a\u7a3f\u5b50\u3002 \u8fd9\u4e2a\u6211\u8bb2\u4e86\u4e00\u822c\u662f\u4f1a terminate \u6216\u8005\u662f undefined behavior\uff0ceffective C++\u539f\u6587\u4e5f\u662f\u8fd9\u4e48\u5199\u7684\u3002\u6211\u4e0b\u56de\u66f4\u4e25\u8c28\u4e00\u70b9\uff0cfact check \u4e00\u4e0b\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4937930\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : dorafmon <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wutiantong \u4e66\u91cc\u7684\u539f\u6587\uff1a \u201cDepending on the precise conditions under<br \/>which such pairs of simultaneously active exceptions arise, program execution either terminates or yields undefined<br \/>behavior\u201d\uff0c \u8003\u8651\u5230\u4e66\u633a\u8001\u7684\u786e\u5b9e\u6211\u5e94\u8be5\u66f4\u4e25\u8c28\u4e00\u70b9\uff0c\u4f46\u662f\u8fd9\u4e2a point \u6ca1\u600e\u4e48\u53d8\uff0c\u8fd8\u662f\u4e0d\u9f13\u52b1\u5927\u5bb6 throw \u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4937931\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wutiantong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @dorafmon <\/p>\n<p>\u662f\u6709\u8fd9\u6837\u7684\u8bf4\u6cd5\uff0c\u4f46\u65e2\u7136\u4e0d\u662f ub \u5c31\u53ef\u4ee5\u5728\u5145\u5206\u4e86\u89e3\u7684\u524d\u63d0\u4e0b\u52a0\u4ee5\u5229\u7528\u3002<\/p>\n<p>\u6211\u5012\u60f3\u8003\u8003\uff0c\u4f60\u80fd\u7b80\u6d01\u5730\u8bb2\u6e05\u695a noexcept \u5e94\u8be5\u600e\u4e48\u5199\u4e48\uff1f                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4937932\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : dorafmon <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wutiantong \u6211\u505a\u8fd9\u4e2a\u89c6\u9891\u7684\u53ea\u662f\u60f3\u7ed9\u666e\u901a\u7684\u65b0\u5165\u884c c++\u7a0b\u5e8f\u5458\u63d0\u4f9b\u4e00\u70b9\u793e\u533a\u5185\u90fd\u77e5\u9053\u7684\u5e38\u8bc6\u3002\u6240\u4ee5\u6709\u4e9b\u65f6\u5019\u6709\u4e9b\u7279\u6b8a\u60c5\u51b5\u6211\u5c31\u6ca1\u6709\u63d0\uff0c\u6709\u4e9b\u7279\u522b\u7ec6\u8282\u7684\u4e1c\u897f\u6211\u81ea\u5df1\u4e5f\u4f1a\u6709\u6240\u53d6\u820d\uff0c\u6211\u89c9\u5f97\u4e0d\u9f13\u52b1\u5927\u5bb6\u5728 destructor throw exception \u5176\u5b9e\u7b97\u662f\u4e1a\u754c\u7684\u4e00\u4e2a\u666e\u904d\u770b\u6cd5\u3002<\/p>\n<p>noexcept \u8fd9\u4e2a\u95ee\u9898\u6211\u53ef\u80fd\u8981\u505a\u70b9\u7814\u7a76\u624d\u80fd\u5b8c\u6574\u7684\u56de\u7b54\u4f60\uff0c\u4f46\u662f\u6211\u76ee\u524d\u7684\u770b\u6cd5\u662f\u4e0d\u8981\u968f\u4fbf\u4e71\u52a0 noexcept\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u4f1a\u6210\u4e3a\u4f60 api specification \u7684\u4e00\u90e8\u5206\uff0c\u4f60\u7684 function \u4ee5\u540e\u5982\u679c\u8981 throw \u7684\u8bdd\u5c31\u610f\u5473\u7740\u4f60\u8981\u6539\u53d8\u8fd9\u4e2a spec\uff0c\u6240\u4ee5\u5728\u4f60\u4e0d\u662f\u975e\u5e38\u786e\u5b9a\u7684\u60c5\u51b5\u4e0b\u6682\u65f6\u4e0d\u8981\u52a0 noexcept \u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4937933\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wutiantong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @dorafmon <\/p>\n<p>\u8fd9\u4e2a\u77e5\u8bc6\u70b9\u662f\u6ca1\u95ee\u9898\u7684\uff0c\u4f46\u4f60\u7684\u8bba\u8ff0\u53ef\u80fd\u662f\u6709\u95ee\u9898\u7684\u3002<\/p>\n<p>\u6211\u4eec\u5728 C++ Core Guidelines \u4e2d\u53ef\u4ee5\u627e\u5230\u5173\u4e8e\u8fd9\u4e2a\u77e5\u8bc6\u70b9\u66f4\u6e05\u6670\u66f4\u6b63\u786e\u7684\u8bba\u8ff0\uff1a<\/p>\n<p>https:\/\/github.com\/isocpp\/CppCoreGuidelines\/blob\/master\/CppCoreGuidelines.md#Rc-dtor-fail                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4937934\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wutiantong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @dorafmon \u4f60\u6ca1\u6709\u8ba4\u8bc6\u5230 noexcept \u8fd9\u4e2a\u5173\u952e\u8bcd\u7684\u8bbe\u8ba1\u610f\u56fe                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4937935\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : dorafmon <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wutiantong \u55ef\u55ef\uff0c\u53d7\u6559\u4e86\uff0c\u6211\u518d\u6253\u78e8\u6253\u78e8\u81ea\u5df1\u3002\u5173\u4e8e\u8fd9\u4e2a noexcept\uff0c\u60a8\u80fd\u66f4\u8be6\u7ec6\u7684\u8bb2\u8bb2\u4e48\uff1f\u8c22\u8c22\uff01\u6211\u81ea\u5df1\u4e5f\u60f3\u5b66\u4e60\u5b66\u4e60\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u65b0\u624b C++ Developer&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/279886"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=279886"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/279886\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=279886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=279886"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=279886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}