{"id":937,"date":"2021-12-19T02:22:37","date_gmt":"2021-12-18T18:22:37","guid":{"rendered":"https:\/\/blog.cauchyschwarz.com\/?p=937"},"modified":"2021-12-19T02:24:31","modified_gmt":"2021-12-18T18:24:31","slug":"modern-c","status":"publish","type":"post","link":"https:\/\/blog.cauchyschwarz.com\/?p=937","title":{"rendered":"Modern C++"},"content":{"rendered":"\n<p>\u6309\u7167\u5fae\u8f6f\u4e3avisual studio\u51c6\u5907\u7684c++\u6587\u6863\u91cd\u65b0\u5b66\u4e60\u548c\u68b3\u7406\u4e00\u4e0b\u81ea\u5df1\u7684c++\u77e5\u8bc6\uff0c\u53ea\u8003\u8651\u901a\u7528 \u7684\u90e8\u5206\uff0c\u4e0d\u8003\u8651\u53ea\u5728windows\u5e73\u53f0\u4e0a\u63d0\u4f9b\u7684c++\u7279\u6027\u3002<br><a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/cpp\/cpp-language-reference\">\u539f\u6587\u6863\u5730\u5740<\/a><\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-right counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69e5f9ed7f38f\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69e5f9ed7f38f\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#Modern_C\" >Modern C++<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#Modern_C%E7%9A%84%E7%B1%BB%E5%9E%8B%E7%B3%BB%E7%BB%9F\" >Modern C++\u7684\u7c7b\u578b\u7cfb\u7edf<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E5%80%BC%E7%B1%BB%E5%9E%8BValue_Types\" >\u503c\u7c7b\u578b(Value Types)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E6%8B%B7%E8%B4%9D%E7%9A%84%E4%BC%98%E5%8C%96move%E8%AF%AD%E4%B9%89\" >\u62f7\u8d1d\u7684\u4f18\u5316,move\u8bed\u4e49<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E6%98%BE%E7%A4%BA%E7%9A%84%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2Explicit_conversionscasts\" >\u663e\u793a\u7684\u7c7b\u578b\u8f6c\u6362Explicit conversions(casts)<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E7%BB%9F%E4%B8%80%E5%88%9D%E5%A7%8B%E5%8C%96%E5%92%8C%E5%A7%94%E6%89%98%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0Uniform_Initialization_and_Dlegating_Constructors\" >\u7edf\u4e00\u521d\u59cb\u5316\u548c\u59d4\u6258\u6784\u9020\u51fd\u6570(Uniform Initialization and Dlegating Constructors)<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E7%94%A8%E8%8A%B1%E6%8B%AC%E5%8F%B7%E5%88%9D%E5%A7%8B%E5%8C%96Brace_Initialization\" >\u7528\u82b1\u62ec\u53f7\u521d\u59cb\u5316(Brace Initialization)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#initializer_list_Constructors\" >initializer_list&nbsp;Constructors<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E5%A7%94%E6%89%98%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0Delegating_Constructors\" >\u59d4\u6258\u6784\u9020\u51fd\u6570(Delegating Constructors)<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%A3%B0%E6%98%8E%E5%91%A8%E6%9C%9F%E5%92%8C%E8%B5%84%E6%BA%90%E7%AE%A1%E7%90%86\" >\u5bf9\u8c61\u7684\u58f0\u660e\u5468\u671f\u548c\u8d44\u6e90\u7ba1\u7406<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#RAIIResource_acquisition_is_initialization\" >RAII(Resource acquisition is initialization)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E6%99%BA%E8%83%BD%E6%8C%87%E9%92%88Smart_Pointers\" >\u667a\u80fd\u6307\u9488(Smart Pointers)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%92%8CIO%E7%9A%84%E6%A0%BC%E5%BC%8F%E5%8C%96\" >\u5b57\u7b26\u4e32\u548cI\/O\u7684\u683c\u5f0f\u5316<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E9%94%99%E8%AF%AF%E5%92%8C%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86\" >\u9519\u8bef\u548c\u5f02\u5e38\u5904\u7406<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E8%AF%8D%E6%B3%95%E7%BA%A6%E5%AE%9A\" >\u8bcd\u6cd5\u7ea6\u5b9a<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E6%B3%A8%E9%87%8A\" >\u6ce8\u91ca<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E6%95%B0%E5%80%BC%EF%BC%8C%E5%B8%83%E5%B0%94%E7%B1%BB%E5%9E%8B%E5%92%8C%E6%8C%87%E9%92%88%E7%9A%84%E5%AD%97%E9%9D%A2%E5%80%BC\" >\u6570\u503c\uff0c\u5e03\u5c14\u7c7b\u578b\u548c\u6307\u9488\u7684\u5b57\u9762\u503c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%92%8C%E5%AD%97%E7%AC%A6%E7%9A%84%E5%AD%97%E9%9D%A2%E5%80%BC\" >\u5b57\u7b26\u4e32\u548c\u5b57\u7b26\u7684\u5b57\u9762\u503c<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#Universal_character_names\" >Universal character names<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E7%94%A8%E6%88%B7%E5%AE%9A%E4%B9%89%E7%9A%84%E5%AD%97%E9%9D%A2%E5%80%BC\" >\u7528\u6237\u5b9a\u4e49\u7684\u5b57\u9762\u503c<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5\" >\u57fa\u672c\u6982\u5ff5<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E5%A3%B0%E6%98%8E%E5%92%8C%E5%AE%9A%E4%B9%89\" >\u58f0\u660e\u548c\u5b9a\u4e49<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E5%9F%BA%E7%A1%80%E7%B1%BB%E5%9E%8B\" >\u57fa\u7840\u7c7b\u578b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E5%86%85%E7%BD%AE%E8%BF%90%E7%AE%97%E7%AC%A6%E5%8F%8A%E5%85%B6%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7\" >\u5185\u7f6e\u8fd0\u7b97\u7b26\u53ca\u5176\u4f18\u5148\u7ea7\u548c\u7ed3\u5408\u6027<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E8%A1%A8%E8%BE%BE%E5%BC%8F\" >\u8868\u8fbe\u5f0f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E8%AF%AD%E5%8F%A5\" >\u8bed\u53e5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4\" >\u547d\u540d\u7a7a\u95f4<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E6%9E%9A%E4%B8%BE%E7%B1%BB%E5%9E%8B\" >\u679a\u4e3e\u7c7b\u578b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E8%81%94%E5%90%88%E7%B1%BB%E5%9E%8B\" >\u8054\u5408\u7c7b\u578b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E5%87%BD%E6%95%B0\" >\u51fd\u6570<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E8%BF%90%E7%AE%97%E7%AC%A6%E9%87%8D%E8%BD%BD\" >\u8fd0\u7b97\u7b26\u91cd\u8f7d<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E7%B1%BB%E5%92%8C%E7%BB%93%E6%9E%84%E4%BD%93\" >\u7c7b\u548c\u7ed3\u6784\u4f53<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-33\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#lambda%E8%A1%A8%E8%BE%BE%E5%BC%8F\" >lambda\u8868\u8fbe\u5f0f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-34\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E6%95%B0%E7%BB%84\" >\u6570\u7ec4<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-35\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E5%BC%95%E7%94%A8\" >\u5f15\u7528<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-36\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E6%8C%87%E9%92%88\" >\u6307\u9488<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-37\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86\" >\u5f02\u5e38\u5904\u7406<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-38\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#trythrow%E5%92%8Ccatch%E8%AF%AD%E5%8F%A5\" >try,throw\u548ccatch\u8bed\u53e5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-39\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#catch%E8%AF%AD%E5%8F%A5%E7%9A%84%E5%8C%B9%E9%85%8D\" >catch\u8bed\u53e5\u7684\u5339\u914d<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-40\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#stack_unwinding\" >stack unwinding<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-41\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#exception_specification\" >exception specification<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-42\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E6%9C%AA%E8%A2%AB%E6%8D%95%E8%8E%B7%E7%9A%84%E5%BC%82%E5%B8%B8\" >\u672a\u88ab\u6355\u83b7\u7684\u5f02\u5e38<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-43\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E6%96%AD%E8%A8%80%E5%92%8C%E7%94%A8%E6%88%B7%E6%8F%90%E4%BE%9B%E7%9A%84%E4%BF%A1%E6%81%AF\" >\u65ad\u8a00\u548c\u7528\u6237\u63d0\u4f9b\u7684\u4fe1\u606f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-44\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E6%A8%A1%E6%9D%BF\" >\u6a21\u677f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-45\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#Event_Handling\" >Event Handling<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-46\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#%E4%B8%80%E3%80%81%E5%9F%BA%E7%A1%80\" >\u4e00\u3001\u57fa\u7840<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-47\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#2%E8%BF%90%E7%AE%97%E4%BC%98%E5%85%88%E7%BA%A7\" >2.\u8fd0\u7b97\u4f18\u5148\u7ea7<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-48\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#3%E5%87%BD%E6%95%B0%E5%8F%82%E6%95%B0%E9%BB%98%E8%AE%A4%E5%80%BC\" >3.\u51fd\u6570\u53c2\u6570\u9ed8\u8ba4\u503c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-49\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#4%E5%9C%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E5%88%97%E8%A1%A8%E4%B8%AD%E5%88%9D%E5%A7%8B%E5%8C%96const%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F\" >4.\u5728\u521d\u59cb\u5316\u5217\u8868\u4e2d\u521d\u59cb\u5316const\u6210\u5458\u53d8\u91cf<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-50\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#5%E4%BD%BF%E7%94%A8%E5%8F%8B%E5%85%83%E5%87%BD%E6%95%B0%E6%88%96%E8%80%85friend_class%E6%9D%A5%E8%AE%BF%E9%97%AEprivate%E5%8F%98%E9%87%8F%E6%88%96%E6%88%90%E5%91%98%E5%87%BD%E6%95%B0\" >5.\u4f7f\u7528\u53cb\u5143\u51fd\u6570\u6216\u8005friend class\u6765\u8bbf\u95eeprivate\u53d8\u91cf\u6216\u6210\u5458\u51fd\u6570<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-51\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#6%E4%B8%8D%E8%83%BD%E8%A2%AB%E9%87%8D%E8%BD%BD%E7%9A%84%E8%BF%90%E7%AE%97%E7%AC%A6\" >6.\u4e0d\u80fd\u88ab\u91cd\u8f7d\u7684\u8fd0\u7b97\u7b26<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-52\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=937\/#7%E5%89%8D%E7%BD%AE%E5%90%8E%E7%BD%AE%E8%87%AA%E5%A2%9E%E5%87%8F%E8%BF%90%E7%AE%97%E7%AC%A6%E7%9A%84%E9%87%8D%E8%BD%BD%E5%A3%B0%E6%98%8E\" >7.\u524d\u7f6e\/\u540e\u7f6e\u81ea\u589e\/\u51cf\u8fd0\u7b97\u7b26\u7684\u91cd\u8f7d\u58f0\u660e<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1 class=\"wp-block-heading\" id=\"modern-c\"><span class=\"ez-toc-section\" id=\"Modern_C\"><\/span>Modern C++<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>Modern C++\u4e0eC-style C++\u7684\u6bd4\u8f83\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Stack-based scope instead of heap or static global scope<\/li><li>\u81ea\u52a8\u7684\u7c7b\u578b\u63a8\u5bfc\u548c\u5f15\u7528\u800c\u4e0d\u662f\u663e\u793a\u7684\u6307\u5b9a\u7c7b\u578b\u540d\u5b57<\/li><li>\u4f7f\u7528\u667a\u80fd\u6307\u9488\u800c\u4e0d\u662f\u539f\u59cb\u6307\u9488<\/li><li>\u5bf9\u4e8e\u5b57\u7b26\u4e32\u4f7f\u7528<code>std::string<\/code>\u548c<code>std::wstring<\/code>\u7c7b\u578b\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u539f\u59cb\u7684\u5b57\u7b26\u4e32\u6570\u7ec4<code>char[]<\/code><\/li><li>\u4f7f\u7528C++\u6807\u51c6\u5e93\u63d0\u4f9b\u7684\u5bb9\u5668\u800c\u4e0d\u662f\u539f\u59cb\u6570\u7ec4\u548c\u81ea\u5b9a\u4e49\u5bb9\u5668<\/li><li>\u4f7f\u7528C++\u6807\u51c6\u5e93\u63d0\u4f9b\u7684\u7b97\u6cd5\u800c\u4e0d\u662f\u81ea\u5df1\u5199\u7684<\/li><li>\u4f7f\u7528\u5f02\u5e38\u5904\u7406\u5404\u79cd\u51fa\u9519\u72b6\u51b5<\/li><li>\u4f7f\u7528C++\u6807\u51c6\u5e93\u63d0\u4f9b\u7684Lock-free\u7684\u7ebf\u7a0b\u95f4\u901a\u4fe1\u673a\u5236\u800c\u4e0d\u662f\u5176\u4ed6\u7684(\u53ef\u80fd\u6709\u9501\u7684)\u7ebf\u7a0b\u95f4\u901a\u4fe1\u673a\u5236<\/li><li>Inline lambda\u51fd\u6570<\/li><li>\u57fa\u4e8e\u8303\u56f4\u7684for\u5faa\u73af<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"modern-c%E7%9A%84%E7%B1%BB%E5%9E%8B%E7%B3%BB%E7%BB%9F\"><span class=\"ez-toc-section\" id=\"Modern_C%E7%9A%84%E7%B1%BB%E5%9E%8B%E7%B3%BB%E7%BB%9F\"><\/span>Modern C++\u7684\u7c7b\u578b\u7cfb\u7edf<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u53d8\u91cf(variable)<\/li><li>\u5bf9\u8c61(object)<\/li><li>POD\u7c7b\u578b(POD type, plain old data)<br>\u6ca1\u592a\u5f04\u6e05\u5177\u4f53\u5b9a\u4e49\uff0c\u53cd\u6b63\u8bb0\u4f4fC\u91cc\u9762\u53ea\u6709POD\u7c7b\u578b\u5c31\u597d\u4e86<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"%E5%80%BC%E7%B1%BB%E5%9E%8Bvalue-types\"><span class=\"ez-toc-section\" id=\"%E5%80%BC%E7%B1%BB%E5%9E%8BValue_Types\"><\/span>\u503c\u7c7b\u578b(Value Types)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>C++\u91cc\u7684\u7c7b\u9ed8\u8ba4\u662fvalues types\u3002<br>\u5173\u4e8e\u503c\u7c7b\u578b(Value Types)\u548c\u5f15\u7528\u7c7b\u578b(Reference Types)\u7684\u8fa8\u6790\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>As previously stated, C++ classes are by default value types. They can be specified as reference types, which enable polymorphic behavior to support object-oriented programming. Value types are sometimes viewed from the perspective of memory and layout control, whereas reference types are about base classes and virtual functions for polymorphic purposes. By default, value types are copyable, which means there is always a copy constructor and a copy assignment operator. For reference types, you make the class non-copyable (disable the copy constructor and copy assignment operator) and use a virtual destructor, which supports their intended polymorphism. Value types are also about the contents, which, when they are copied, always give you two independent values that can be modified separately. Reference types are about identity &#8211; what kind of object is it? For this reason, &#8220;reference types&#8221; are also referred to as &#8220;polymorphic types&#8221;.<\/p><\/blockquote>\n\n\n\n<p><strong>\u5982\u4f55\u58f0\u660e\u4e00\u4e2aReference Type\uff1f<\/strong><\/p>\n\n\n\n<p>\u6ca1\u6709\u8bed\u6cd5\u4e0a\u7684\u6807\u51c6\u65b9\u6cd5\uff0c\u53ea\u8981\u4ece\u529f\u80fd\u4e0a\u8ba9\u8fd9\u4e2a\u7c7b\u7684\u590d\u5236\u6784\u9020\u51fd\u6570\u548c\u8d4b\u503c\u51fd\u6570\u4e0d\u80fd\u7528\u5c31\u884c\u4e86\u3002\u6bd4\u5982\u5c06\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u8bbe\u7f6e\u4e3aprivate\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\"><em>\/\/ cl \/EHsc \/nologo \/W4  <\/em>\n\nclass MyRefType {  \nprivate:  \n    MyRefType &amp; operator=(const MyRefType &amp;);  \n    MyRefType(const MyRefType &amp;);  \npublic:  \n    MyRefType () {}  \n};  \n\nint main()  \n{  \n    MyRefType Data1, Data2;  \n    <em>\/\/ ...  <\/em>\n    Data1 = Data2;  \n}  \n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"%E6%8B%B7%E8%B4%9D%E7%9A%84%E4%BC%98%E5%8C%96move%E8%AF%AD%E4%B9%89\"><span class=\"ez-toc-section\" id=\"%E6%8B%B7%E8%B4%9D%E7%9A%84%E4%BC%98%E5%8C%96move%E8%AF%AD%E4%B9%89\"><\/span>\u62f7\u8d1d\u7684\u4f18\u5316,move\u8bed\u4e49<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u901a\u8fc7\u7528\u53f3\u503c\u5f15\u7528\u4f5c\u4e3a\u53c2\u6570\u6765\u5b9a\u4e49move construction\u548cmove assignment\uff0c\u51cf\u5c11\u5185\u5b58\u62f7\u8d1d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">#include &lt;memory&gt;  \n#include &lt;stdexcept&gt;  \nusing namespace std;  \n<em>\/\/ ...  <\/em>\nclass my_class {  \n    unique_ptr&lt;BigHugeData&gt; data;  \npublic:  \n    my_class( my_class&amp;&amp; other )   <em>\/\/ move construction  <\/em>\n        : data( move( other.data ) ) { }  \n    my_class&amp; operator=( my_class&amp;&amp; other )   <em>\/\/ move assignment  <\/em>\n    { data = move( other.data ); return *this; }  \n    <em>\/\/ ...  <\/em>\n    void method() {   <em>\/\/ check (if appropriate)  <\/em>\n        if( !data )   \n            throw std::runtime_error(\"RUNTIME ERROR: Insufficient resources!\");  \n    }  \n};  \n<\/code><\/pre>\n\n\n\n<p>move-only \u7c7b\u578b\uff1a\u53ea\u80fdmove\uff0c\u4e0d\u80fd\u62f7\u8d1d\u3002<br><strong>\u5173\u4e8e\u8fd9\u4e2amove\u65b9\u6cd5\uff0c\u73b0\u5728\u8fd8\u4e0d\u662f\u5f88\u6e05\u695a\u5230\u5e95\u5e72\u4e86\u4ec0\u4e48\u548c\u6709\u4ec0\u4e48\u4f18\u70b9\uff0c\u5148\u8bb0\u5728\u8fd9\u91cc\u540e\u9762\u518d\u8865\u5145\u3002<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"%E6%98%BE%E7%A4%BA%E7%9A%84%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2explicit-conversionscasts\"><span class=\"ez-toc-section\" id=\"%E6%98%BE%E7%A4%BA%E7%9A%84%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2Explicit_conversionscasts\"><\/span>\u663e\u793a\u7684\u7c7b\u578b\u8f6c\u6362Explicit conversions(casts)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>C-style\u7684\u4e24\u79cd\u5f3a\u5236\u8f6c\u6362\uff0c\u6548\u679c\u7b49\u4ef7\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">(int) x; <em>\/\/ old-style cast, old-style syntax  <\/em>\nint(x); <em>\/\/ old-style cast, functional syntax<\/em>\n<\/code><\/pre>\n\n\n\n<p>\u66f4\u597d\u7684\u5f3a\u5236\u8f6c\u6362\u662f\u4f7f\u7528\u4e0b\u9762\u4e4b\u4e00\u7684\u8fd0\u7b97\u7b26(\u4e00\u4e2a\u660e\u663e\u7684\u597d\u5904\u662f\u66f4\u5bb9\u6613\u627e\u5230\u4ee3\u7801\u4e2d\u4f7f\u7528\u4e86\u5f3a\u5236\u8f6c\u6362\u7684\u5730\u65b9)\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>static_cast<\/code><br>\u53ea\u5728\u7f16\u8bd1\u65f6\u68c0\u67e5\u8fd9\u7c7b\u8f6c\u6362\u3002\u53ef\u4ee5\u7528\u4e8ecompatible\u7684\u7c7b\u578b\u4e4b\u95f4\u7684\u5f3a\u5236\u8f6c\u6362\u3002<\/li><li><code>dynamic_cast<\/code><br>\u5728\u8fd0\u884c\u65f6\u591a\u82b1\u8d39\u70b9\u7b97\u529b\u6765\u68c0\u67e5\u8fd9\u4e2apointer-to-base\u5230pointer-to-derived\u7684<code>dynamic_cast<\/code>\u662f\u5426\u6709\u6548\u3002<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">Base* b = new Base();  \n\n<em>\/\/ Run-time check to determine whether b is actually a Derived*  <\/em>\nDerived* d3 = dynamic_cast&lt;Derived*&gt;(b);  \n\n<em>\/\/ If b was originally a Derived*, then d3 is a valid pointer.  <\/em>\nif(d3)  \n{  \n   <em>\/\/ Safe to call Derived method.  <\/em>\n   cout &lt;&lt; d3-&gt;DoSomethingMore() &lt;&lt; endl;  \n}  \nelse  \n{  \n   <em>\/\/ Run-time check failed.  <\/em>\n   cout &lt;&lt; \"d3 is null\" &lt;&lt; endl;  \n}  \n\n<em>\/\/Output: d3 is null;<\/em>\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><code>const_cast<\/code><br>\u5c06\u53d8\u91cf\u7684const\u5c5e\u6027\u7ed9\u53bb\u6389\u6216\u8005\u53cd\u8fc7\u6765\u7ed9\u53d8\u91cf\u52a0\u4e0aconst\u5c5e\u6027\u3002<\/li><li><code>reinterpret_cast<\/code><br>\u7528\u4e8e\u4e24\u4e2a\u5b8c\u5168\u4e0d\u76f8\u5173\u7684\u7c7b\u578b\u4e4b\u95f4\u7684\u8f6c\u6362\u3002\u8fd9\u4e2a\u5c31\u6bd4\u8f83\u63a5\u8fd1C-style\u7684\u663e\u793a\u5f3a\u5236\u8f6c\u6362\u4e86\u3002<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E7%BB%9F%E4%B8%80%E5%88%9D%E5%A7%8B%E5%8C%96%E5%92%8C%E5%A7%94%E6%89%98%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0uniform-initialization-and-dlegating-constructors\"><span class=\"ez-toc-section\" id=\"%E7%BB%9F%E4%B8%80%E5%88%9D%E5%A7%8B%E5%8C%96%E5%92%8C%E5%A7%94%E6%89%98%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0Uniform_Initialization_and_Dlegating_Constructors\"><\/span>\u7edf\u4e00\u521d\u59cb\u5316\u548c\u59d4\u6258\u6784\u9020\u51fd\u6570(Uniform Initialization and Dlegating Constructors)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"%E7%94%A8%E8%8A%B1%E6%8B%AC%E5%8F%B7%E5%88%9D%E5%A7%8B%E5%8C%96brace-initialization\"><span class=\"ez-toc-section\" id=\"%E7%94%A8%E8%8A%B1%E6%8B%AC%E5%8F%B7%E5%88%9D%E5%A7%8B%E5%8C%96Brace_Initialization\"><\/span>\u7528\u82b1\u62ec\u53f7\u521d\u59cb\u5316(Brace Initialization)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">#include &lt;string&gt;  \nusing namespace std;  \n\nclass class_a {  \npublic:  \n    class_a() {}  \n    class_a(string str) : m_string{ str } {}  \n    class_a(string str, double dbl) : m_string{ str }, m_double{ dbl } {}  \ndouble m_double;  \nstring m_string;  \n};  \n\nint main()  \n{  \n    class_a c1{};  \n    class_a c1_1;  \n\n    class_a c2{ \"ww\" };  \n    class_a c2_1(\"xx\");  \n\n    <em>\/\/ order of parameters is the same as the constructor  <\/em>\n    class_a c3{ \"yy\", 4.4 };  \n    class_a c3_1(\"zz\", 5.5);  \n}\n<\/code><\/pre>\n\n\n\n<p>\u5f53\u7c7b\u6709\u975e\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\u65f6\uff0c\u7528\u82b1\u62ec\u53f7\u53bb\u521d\u59cb\u5316\u53d8\u91cf\uff0c\u7f16\u8bd1\u5668\u4f1a\u6309\u7167\u53c2\u6570\u7684\u6570\u76ee\u548c\u987a\u5e8f\u53bb\u5339\u914d\u6784\u9020\u51fd\u6570\uff0c \u5982\u679c\u7c7b\u6ca1\u6709\u975e\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\uff0c\u90a3\u4e48\u5c31\u6309\u7c7b\u7684\u6210\u5458\u53d8\u91cf\u7684\u987a\u5e8f\u548c\u82b1\u62ec\u53f7\u91cc\u7684\u5185\u5bb9\u53bb\u521d\u59cb\u5316\u53d8\u91cf\u3002<br>\u5982\u679c\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\u88ab\u6bd4\u8f83\u4e3adelete\uff0c\u90a3\u4e48\u901a\u8fc7\u7a7a\u82b1\u62ec\u53f7\u6765\u8c03\u7528\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\u7684\u65b9\u5f0f\u4e0d\u53ef\u7528\u3002<br>\u53ef\u4ee5\u5728\u4efb\u4f55\u9700\u8981\u521d\u59cb\u5316\u53d8\u91cf\u7684\u5730\u65b9\u4f7f\u7528\u82b1\u62ec\u53f7\u521d\u59cb\u5316\u8fd9\u79cd\u65b9\u5f0f\u6765\u521d\u59cb\u5316\u53d8\u91cf\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"initializerlist-constructors\"><span class=\"ez-toc-section\" id=\"initializer_list_Constructors\"><\/span><code>initializer_list<\/code>&nbsp;Constructors<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u53ef\u4ee5\u4e13\u95e8\u7528\u4e00\u4e2a<code>initializer_list<\/code>\u6765\u4fdd\u5b58\u4e0a\u9762\u6240\u8bf4\u7684\u82b1\u62ec\u53f7\u7684\u5bf9\u8c61\u5217\u8868\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">#include &lt;initializer_list&gt;\ninitializer_list&lt;int&gt; int_list{5, 6, 7};  \n<\/code><\/pre>\n\n\n\n<p><code>initializer_list<\/code>\u53d8\u91cf\u53ef\u4ee5\u62f7\u8d1d\uff0c\u53ea\u662f\u62f7\u8d1d\u540e\u7684\u53d8\u91cf\u7684\u6210\u5458\u662f\u88ab\u62f7\u8d1d\u7684\u53d8\u91cf\u7684\u6210\u5458\u7684\u5f15\u7528\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">initializer_list&lt;int&gt; ilist1{ 5, 6, 7 };  \ninitializer_list&lt;int&gt; ilist2( ilist1 );  \nif (ilist1.begin() == ilist2.begin())  \n    cout &lt;&lt; \"yes\" &lt;&lt; endl; <em>\/\/ expect \"yes\"  <\/em>\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"%E5%A7%94%E6%89%98%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0delegating-constructors\"><span class=\"ez-toc-section\" id=\"%E5%A7%94%E6%89%98%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0Delegating_Constructors\"><\/span>\u59d4\u6258\u6784\u9020\u51fd\u6570(Delegating Constructors)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><code>constructor (. . .) : constructor (. . .)<\/code><br>\u5728\u4f7f\u7528\u59d4\u6258\u6784\u9020\u51fd\u6570\u65f6\uff0c\u4e0d\u80fd\u540c\u65f6\u4f7f\u7528\u5217\u8868\u521d\u59cb\u5316\u6210\u5458\u53d8\u91cf\uff0c\u5373<code>constructor(...) : constructor( ...), member1(value1), member2(value2)...<\/code>\u6216\u8005<code>constructor(...) : member1(value1), member2(value2), ... constructor(...)<\/code>\u662f\u4e0d\u5141\u8bb8\u7684\u3002<br>\u4f7f\u7528\u59d4\u6258\u6784\u9020\u51fd\u6570\u65f6\uff0c\u4f1a\u5148\u8c03\u7528\u6210\u5458\u53d8\u91cf\u81ea\u5df1\u7684\u521d\u59cb\u5316\u4ee3\u7801\uff0c\u7136\u540e\u8c03\u7528\u59d4\u6258\u6784\u9020\u51fd\u6570\u6765\u521d\u59cb\u5316\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">class class_a {  \npublic:  \n    class_a() {}  \n    class_a(string str) : m_string{ str } {}  \n    class_a(string str, double dbl) : class_a(str) { m_double = dbl; }  \n    double m_double{ 1.0 };  \n    string m_string{ m_double &lt; 10.0 ? \"alpha\" : \"beta\" };  \n};  \n\nint main() {  \n    class_a a{ \"hello\", 2.0 };  <em>\/\/expect a.m_double == 2.0, a.m_string == \"hello\"  <\/em>\n    int y = 4;  \n}  \n<\/code><\/pre>\n\n\n\n<p>\u5f00\u53d1\u8005\u9700\u8981\u907f\u514d\u59d4\u6258\u6784\u9020\u51fd\u6570\u7684\u8c03\u7528\u94fe\u4e0d\u4f1a\u5f62\u6210\u4e00\u4e2a\u73af\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%A3%B0%E6%98%8E%E5%91%A8%E6%9C%9F%E5%92%8C%E8%B5%84%E6%BA%90%E7%AE%A1%E7%90%86\"><span class=\"ez-toc-section\" id=\"%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%A3%B0%E6%98%8E%E5%91%A8%E6%9C%9F%E5%92%8C%E8%B5%84%E6%BA%90%E7%AE%A1%E7%90%86\"><\/span>\u5bf9\u8c61\u7684\u58f0\u660e\u5468\u671f\u548c\u8d44\u6e90\u7ba1\u7406<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>As long as there are no cycles and every link in the DAG is represented by an object that has a destructor (instead of a raw pointer, handle, or other mechanism), then resource leaks are impossible because the language prevents them.<\/p><\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>You can use raw pointers for non-ownership and observation. A non-owning pointer may dangle, but it can\u2019t leak.<\/p><\/blockquote>\n\n\n\n<p>\u6240\u4ee5\u5173\u952e\u5728\u4e8e\u4e0d\u8981\u7528raw pointer\u6765own resource\uff0c\u5c31\u4e0d\u7528\u62c5\u5fc3\u8d44\u6e90\u6cc4\u9732\u3002<\/p>\n\n\n\n<p><strong>\u5bb9\u6613\u51fa\u95ee\u9898\u7684static\u53d8\u91cf<\/strong>\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Use static lifetime sparingly (global static, function local static) because problems can arise. What happens when the constructor of a global object throws an exception? Typically, the app faults in a way that can be difficult to debug. Construction order is problematic for static lifetime objects, and is not concurrency-safe. Not only is object construction a problem, destruction order can be complex, especially where polymorphism is involved. Even if your object or variable isn\u2019t polymorphic and doesn&#8217;t have complex construction\/destruction ordering, there\u2019s still the issue of thread-safe concurrency. A multithreaded app can\u2019t safely modify the data in static objects without having thread-local storage, resource locks, and other special precautions.<\/p><\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"raiiresource-acquisition-is-initialization\"><span class=\"ez-toc-section\" id=\"RAIIResource_acquisition_is_initialization\"><\/span>RAII(Resource acquisition is initialization)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u786e\u4fdd\u5bf9\u8c61\u62e5\u6709\u5176\u5bf9\u5e94\u7684\u8d44\u6e90\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E6%99%BA%E8%83%BD%E6%8C%87%E9%92%88smart-pointers\"><span class=\"ez-toc-section\" id=\"%E6%99%BA%E8%83%BD%E6%8C%87%E9%92%88Smart_Pointers\"><\/span>\u667a\u80fd\u6307\u9488(Smart Pointers)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4f7f\u7528\u667a\u80fd\u6307\u9488\u6765\u5e2e\u52a9\u907f\u514d\u5185\u5b58\u6cc4\u9732\u3001\u8d44\u6e90\u6cc4\u9732\u548c\u5b9e\u73b0\u5f02\u5e38\u5b89\u5168\u3002<br>\u667a\u80fd\u6307\u9488\u7684\u610f\u4e49\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>In practical terms, the main principle of RAII is to give ownership of any heap-allocated resource\u2014for example, dynamically-allocated memory or system object handles\u2014to a stack-allocated object whose destructor contains the code to delete or free the resource and also any associated cleanup code.<\/p><\/blockquote>\n\n\n\n<p>\u53ea\u5728\u5fc5\u8981\u7684\u5730\u65b9\u4f7f\u7528raw pointer\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>In modern C++, raw pointers are only used in small code blocks of limited scope, loops, or helper functions where performance is critical and there is no chance of confusion about ownership.<\/p><\/blockquote>\n\n\n\n<p>\u5fae\u8f6f\u7ed9\u7684\u63d0\u793a\uff1a<\/p>\n\n\n\n<p><strong>Always create smart pointers on a separate line of code, never in a parameter list, so that a subtle resource leak won&#8217;t occur due to certain parameter list allocation rules.<\/strong><\/p>\n\n\n\n<p>C++ Standard Library Smart Pointers<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>unique_ptr<\/code><br>\u53ea\u80fdmove\uff0c\u4e0d\u80fd\u590d\u5236<\/li><li><code>shared_ptr<\/code><br>\u5305\u542b\u540c\u4e00\u4e2a\u6307\u9488\u7684<code>shared_ptr<\/code>\u603b\u662f\u76f8\u7b49\u7684(equal)\uff0c\u5305\u542b\u4e0d\u540c\u6307\u9488\u7684<code>shared_ptr<\/code>\u662f\u4e0d\u7b49\u7684\u3002<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\"><em>\/\/ Initialize two separate raw pointers.<\/em>\n<em>\/\/ Note that they contain the same values.<\/em>\nauto song1 = new Song(L\"Village People\", L\"YMCA\");\nauto song2 = new Song(L\"Village People\", L\"YMCA\");\n\n<em>\/\/ Create two unrelated shared_ptrs.<\/em>\nshared_ptr&lt;Song&gt; p1(song1);    \nshared_ptr&lt;Song&gt; p2(song2);\n\n<em>\/\/ Unrelated shared_ptrs are never equal.<\/em>\nwcout &lt;&lt; \"p1 &lt; p2 = \" &lt;&lt; std::boolalpha &lt;&lt; (p1 &lt; p2) &lt;&lt; endl;\nwcout &lt;&lt; \"p1 == p2 = \" &lt;&lt; std::boolalpha &lt;&lt;(p1 == p2) &lt;&lt; endl;\n\n<em>\/\/ Related shared_ptr instances are always equal.<\/em>\nshared_ptr&lt;Song&gt; p3(p2);\nwcout &lt;&lt; \"p3 == p2 = \" &lt;&lt; std::boolalpha &lt;&lt; (p3 == p2) &lt;&lt; endl; \n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><code>weak_ptr<\/code><br><code>weak_ptr<\/code>\u5b9e\u73b0\u7684\u662fobserver\uff0c\u4e0d\u4f1a\u62e5\u6709\u8d44\u6e90\u3002<\/li><li><em>pimpl idiom<\/em><br><em>pointer to implementation<\/em>\uff0c\u5c31\u662f\u5728\u8981\u66b4\u9732\u51fa\u6765\u7ed9\u522b\u4eba\u7528\u7684\u7c7b\u91cc\u9762\u58f0\u660e\u4e00\u4e2a\u7528\u4e8e\u5b9e\u73b0\u8be5\u7c7b\u7684impl\u7c7b\u548c\u76f8\u5e94\u7684impl\u7c7b\u6307\u9488\uff1b\u7136\u540e\u8fd9\u4e2aimpl\u7c7b\u7684\u5b9e\u73b0\u5199\u5728cpp\u6587\u4ef6\u91cc\u9762\uff0c\u8fd9\u6837\u4fbf\u5b9e\u73b0\u4e86\u5bf9\u7c7b\u7684\u5c01\u88c5\u3002<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\"><em>\/\/ my_class.h  <\/em>\nclass my_class {  \n   <em>\/\/  ... all public and protected stuff goes here ...  <\/em>\nprivate:  \n   class impl; unique_ptr&lt;impl&gt; pimpl; <em>\/\/ opaque type here  <\/em>\n};  \n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\"><em>\/\/ my_class.cpp  <\/em>\nclass my_class::impl {  <em>\/\/ defined privately here  <\/em>\n  <em>\/\/ ... all private data and functions: all of these  <\/em>\n  <em>\/\/     can now change without recompiling callers ...  <\/em>\n};  \nmy_class::my_class(): pimpl( new impl )  \n{  \n  <em>\/\/ ... set impl values ...   <\/em>\n}  \n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%92%8Cio%E7%9A%84%E6%A0%BC%E5%BC%8F%E5%8C%96\"><span class=\"ez-toc-section\" id=\"%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%92%8CIO%E7%9A%84%E6%A0%BC%E5%BC%8F%E5%8C%96\"><\/span>\u5b57\u7b26\u4e32\u548cI\/O\u7684\u683c\u5f0f\u5316<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4f7f\u7528c++\u539f\u751f\u7684&lt;iomanip&gt;\u6765\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u548c\u8f93\u51fa\u662f\u5f88\u6298\u78e8\u4eba\u7684\uff0c\u6240\u4ee5\u5fae\u8f6f\u5efa\u8bae\u4f7f\u7528Boot\u5e93\u91cc\u7684Boost.Format\u6765\u7b80\u5316\u8fd9\u79cd\u5de5\u4f5c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E9%94%99%E8%AF%AF%E5%92%8C%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86\"><span class=\"ez-toc-section\" id=\"%E9%94%99%E8%AF%AF%E5%92%8C%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86\"><\/span>\u9519\u8bef\u548c\u5f02\u5e38\u5904\u7406<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4f7f\u7528asserts\u6765\u68c0\u67e5\u4e0d\u5e94\u8be5\u53d1\u751f\u7684\u9519\u8bef\uff0c\u800c\u4f7f\u7528\u5f02\u5e38\u6765\u68c0\u67e5\u53ef\u80fd\u4f1a\u53d1\u751f\u7684\u9519\u8bef\u3002<\/li><li>\u5f53\u68c0\u6d4b\u9519\u8bef\u7684\u4ee3\u7801\u548c\u5904\u7406\u9519\u8bef\u7684\u4ee3\u7801\u53ef\u4ee5\u8f83\u597d\u5730\u5206\u5f00\u7684\u65f6\u5019\u5c31\u4f7f\u7528\u5f02\u5e38\u3002\u5206\u4e0d\u5f00\u7684\u5730\u65b9\u548c\u6027\u80fd\u5f88\u91cd\u8981\u7684\u5730\u65b9\u5c31\u8003\u8651\u4f7f\u7528\u9519\u8bef\u7801\u5427\u3002<\/li><li>\u5bf9\u4e8e\u4f1a\u629b\u51fa\u5f02\u5e38\u6216\u8005\u4f20\u9012\u5f02\u5e38\u7684\u51fd\u6570\uff0c\u5e94\u8be5\u660e\u786e\u6307\u51fa\u8be5\u51fd\u6570\u662fstrong guarantee\u3001basic guarantee\u3001nothrow\u4e09\u79cdexception guarantee\u4e2d\u7684\u54ea\u4e00\u79cd\u3002<\/li><li>\u629b\u51fa\u5f02\u5e38\u65f6by value\uff0c\u6355\u83b7\u5f02\u5e38\u65f6by reference\u3002<\/li><li>\u4e0d\u8981\u4f7f\u7528exception specifications(\u8fd9\u662f\u4ec0\u4e48\uff1f)<\/li><li>\u80fd\u4f7f\u7528\u6807\u51c6\u5e93\u63d0\u4f9b\u7684exception\u5c31\u7528\u6216\u8005\u4f7f\u7528\u7ee7\u627f\u81ea\u6807\u51c6\u5e93\u7684\u5f02\u5e38\u3002<\/li><li>\u4e0d\u8981\u8ba9\u5f02\u5e38\u4ece\u6790\u6784\u51fd\u6570\u6216\u8005memory-deallocation\u51fd\u6570\u91cc\u629b\u51fa\u6765\u3002<\/li><\/ul>\n\n\n\n<p>\u4e09\u79cdException Guarantee\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>No-fail Guarantee<br>No exception would be thrown out of the function.<\/li><li>Strong GuaranteeThe strong guarantee states that if a function goes out of scope because of an exception, it will not leak memory and program state will not be modified. A function that provides a strong guarantee is essentially a transaction that has commit or rollback semantics: either it completely succeeds or it has no effect.<\/li><li>Basic GuaranteeThe basic guarantee is the weakest of the three. However, it might be the best choice when a strong guarantee is too expensive in memory consumption or in performance. The basic guarantee states that if an exception occurs, no memory is leaked and the object is still in a usable state even though the data might have been modified. +<\/li><\/ol>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E8%AF%8D%E6%B3%95%E7%BA%A6%E5%AE%9A\"><span class=\"ez-toc-section\" id=\"%E8%AF%8D%E6%B3%95%E7%BA%A6%E5%AE%9A\"><\/span>\u8bcd\u6cd5\u7ea6\u5b9a<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E6%B3%A8%E9%87%8A\"><span class=\"ez-toc-section\" id=\"%E6%B3%A8%E9%87%8A\"><\/span>\u6ce8\u91ca<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>c++\u7684\u6ce8\u91ca\u91c7\u7528first syntax\uff0c\u4e0d\u5141\u8bb8nested comment\u3002\u5373\u4e0b\u9762\u7684\u6ce8\u91ca\u662f\u4e0d\u5141\u8bb8\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\"><em>\/* outer comments \/* inner comments *\/<\/em> *\/\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E6%95%B0%E5%80%BC%E5%B8%83%E5%B0%94%E7%B1%BB%E5%9E%8B%E5%92%8C%E6%8C%87%E9%92%88%E7%9A%84%E5%AD%97%E9%9D%A2%E5%80%BC\"><span class=\"ez-toc-section\" id=\"%E6%95%B0%E5%80%BC%EF%BC%8C%E5%B8%83%E5%B0%94%E7%B1%BB%E5%9E%8B%E5%92%8C%E6%8C%87%E9%92%88%E7%9A%84%E5%AD%97%E9%9D%A2%E5%80%BC\"><\/span>\u6570\u503c\uff0c\u5e03\u5c14\u7c7b\u578b\u548c\u6307\u9488\u7684\u5b57\u9762\u503c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5bf9\u4e8e\u6d6e\u70b9\u7c7b\u578b\u7684\u6570\uff0c\u9ed8\u8ba4\u662f\u5f53\u505adouble\uff0c\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0F\/f\u540e\u7f00\u8868\u793a\u5c06\u5176\u5f53\u505afloat\uff0c\u6dfb\u52a0L\/l \u540e\u7f00\u8868\u793a\u5c06\u5176\u5f53\u505along double\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%92%8C%E5%AD%97%E7%AC%A6%E7%9A%84%E5%AD%97%E9%9D%A2%E5%80%BC\"><span class=\"ez-toc-section\" id=\"%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%92%8C%E5%AD%97%E7%AC%A6%E7%9A%84%E5%AD%97%E9%9D%A2%E5%80%BC\"><\/span>\u5b57\u7b26\u4e32\u548c\u5b57\u7b26\u7684\u5b57\u9762\u503c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"universal-character-names\"><span class=\"ez-toc-section\" id=\"Universal_character_names\"><\/span>Universal character names<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u7528<code>\\UNNNNNNNN<\/code>\u8868\u793a\u4e00\u4e2a8\u4e2a16\u8fdb\u5236\u6570\u4f4d\u7684Unicode code point\uff0c\u800c\u7528<code>\\uNNNN<\/code>\u8868\u793a\u524d4\u4e2a16 \u8fdb\u5236\u6570\u4f4d\u4e3a0\u7684Unicode code point\u3002<br>c++\u91cc\u7684\u51e0\u79cd\u5b57\u7b26\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>narrow character<br>\u7528\u4e8e\u8868\u793aascii\u5b57\u7b26\uff0c\u5bf9\u5e94<code>char<\/code><\/li><li>UTF-8\u5b57\u7b26<br><code>u8<\/code>\u524d\u7f00\uff0c\u5bf9\u5e94<code>char<\/code><\/li><li>\u5bbd\u5b57\u7b26<br><code>L<\/code>\u524d\u7f00\uff0c\u7528\u4e8e\u8868\u793aUCS-2\u6216\u8005UTF-16\uff0c\u5bf9\u5e94<code>wchar_t<\/code><\/li><li>UTF-16<br><code>u<\/code>\u524d\u7f00\uff0c\u5bf9\u5e94<code>char16_t<\/code><\/li><li>UTF-32<br><code>U<\/code>\u524d\u7f00\uff0c\u5bf9\u5e94<code>char32_t<\/code><\/li><\/ul>\n\n\n\n<p>\u5bf9\u4e8eraw string literal\uff0c\u5219\u5728\u4e0a\u9762\u7684\u524d\u7f00\u540e\u8ffd\u52a0\u4e0a<code>R<\/code>\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">#include &lt;string&gt;  \nusing namespace std::string_literals; <em>\/\/ enables s-suffix for std::string literals  <\/em>\n\nint main()  \n{  \n    <em>\/\/ Character literals  <\/em>\n    auto c0 =   'A'; <em>\/\/ char  <\/em>\n    auto c1 = u8'A'; <em>\/\/ char  <\/em>\n    auto c2 =  L'A'; <em>\/\/ wchar_t  <\/em>\n    auto c3 =  u'A'; <em>\/\/ char16_t  <\/em>\n    auto c4 =  U'A'; <em>\/\/ char32_t  <\/em>\n\n    <em>\/\/ String literals  <\/em>\n    auto s0 =   \"hello\"; <em>\/\/ const char*  <\/em>\n    auto s1 = u8\"hello\"; <em>\/\/ const char*, encoded as UTF-8  <\/em>\n    auto s2 =  L\"hello\"; <em>\/\/ const wchar_t*  <\/em>\n    auto s3 =  u\"hello\"; <em>\/\/ const char16_t*, encoded as UTF-16  <\/em>\n    auto s4 =  U\"hello\"; <em>\/\/ const char32_t*, encoded as UTF-32  <\/em>\n\n    <em>\/\/ Raw string literals containing unescaped \\ and \"  <\/em>\n    auto R0 =   R\"(\"Hello \\ world\")\"; <em>\/\/ const char*  <\/em>\n    auto R1 = u8R\"(\"Hello \\ world\")\"; <em>\/\/ const char*, encoded as UTF-8  <\/em>\n    auto R2 =  LR\"(\"Hello \\ world\")\"; <em>\/\/ const wchar_t*  <\/em>\n    auto R3 =  uR\"(\"Hello \\ world\")\"; <em>\/\/ const char16_t*, encoded as UTF-16  <\/em>\n    auto R4 =  UR\"(\"Hello \\ world\")\"; <em>\/\/ const char32_t*, encoded as UTF-32  <\/em>\n\n    <em>\/\/ Combining string literals with standard s-suffix  <\/em>\n    auto S0 =   \"hello\"s; <em>\/\/ std::string  <\/em>\n    auto S1 = u8\"hello\"s; <em>\/\/ std::string  <\/em>\n    auto S2 =  L\"hello\"s; <em>\/\/ std::wstring  <\/em>\n    auto S3 =  u\"hello\"s; <em>\/\/ std::u16string  <\/em>\n    auto S4 =  U\"hello\"s; <em>\/\/ std::u32string  <\/em>\n\n    <em>\/\/ Combining raw string literals with standard s-suffix  <\/em>\n    auto S5 =   R\"(\"Hello \\ world\")\"s; <em>\/\/ std::string from a raw const char*  <\/em>\n    auto S6 = u8R\"(\"Hello \\ world\")\"s; <em>\/\/ std::string from a raw const char*, encoded as UTF-8  <\/em>\n    auto S7 =  LR\"(\"Hello \\ world\")\"s; <em>\/\/ std::wstring from a raw const wchar_t*  <\/em>\n    auto S8 =  uR\"(\"Hello \\ world\")\"s; <em>\/\/ std::u16string from a raw const char16_t*, encoded as UTF-16  <\/em>\n    auto S9 =  UR\"(\"Hello \\ world\")\"s; <em>\/\/ std::u32string from a raw const char32_t*, encoded as UTF-32  <\/em>\n}  \n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E7%94%A8%E6%88%B7%E5%AE%9A%E4%B9%89%E7%9A%84%E5%AD%97%E9%9D%A2%E5%80%BC\"><span class=\"ez-toc-section\" id=\"%E7%94%A8%E6%88%B7%E5%AE%9A%E4%B9%89%E7%9A%84%E5%AD%97%E9%9D%A2%E5%80%BC\"><\/span>\u7528\u6237\u5b9a\u4e49\u7684\u5b57\u9762\u503c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u901a\u8fc7\u5b9a\u4e49<code>operator \"\"<\/code>\u53ef\u4ee5\u5b9e\u73b0\u76f4\u63a5\u5728\u4ee3\u7801\u91cc\u4f7f\u7528\u590d\u6570\u90a3\u79cd\u6548\u679c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">ReturnType operator \"\" _a(unsigned long long int);   <em>\/\/ Literal operator for user-defined INTEGRAL literal  <\/em>\nReturnType operator \"\" _b(long double);              <em>\/\/ Literal operator for user-defined FLOATING literal  <\/em>\nReturnType operator \"\" _c(char);                     <em>\/\/ Literal operator for user-defined CHARACTER literal  <\/em>\nReturnType operator \"\" _d(wchar_t);                  <em>\/\/ Literal operator for user-defined CHARACTER literal  <\/em>\nReturnType operator \"\" _e(char16_t);                 <em>\/\/ Literal operator for user-defined CHARACTER literal  <\/em>\nReturnType operator \"\" _f(char32_t);                 <em>\/\/ Literal operator for user-defined CHARACTER literal  <\/em>\nReturnType operator \"\" _g(const     char*, size_t);  <em>\/\/ Literal operator for user-defined STRING literal  <\/em>\nReturnType operator \"\" _h(const  wchar_t*, size_t);  <em>\/\/ Literal operator for user-defined STRING literal  <\/em>\nReturnType operator \"\" _i(const char16_t*, size_t);  <em>\/\/ Literal operator for user-defined STRING literal  <\/em>\nReturnType operator \"\" _g(const char32_t*, size_t);  <em>\/\/ Literal operator for user-defined STRING literal  <\/em>\nReturnType operator \"\" _r(const char*);              <em>\/\/ Raw literal operator  <\/em>\ntemplate&lt;char...&gt; ReturnType operator \"\" _t();       <em>\/\/ Literal operator template  <\/em>\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5\"><span class=\"ez-toc-section\" id=\"%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5\"><\/span>\u57fa\u672c\u6982\u5ff5<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E5%A3%B0%E6%98%8E%E5%92%8C%E5%AE%9A%E4%B9%89\"><span class=\"ez-toc-section\" id=\"%E5%A3%B0%E6%98%8E%E5%92%8C%E5%AE%9A%E4%B9%89\"><\/span>\u58f0\u660e\u548c\u5b9a\u4e49<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Overview of Declarators<br>declarator\u6307\u5b9a\u53d8\u91cf\u540d\uff0c\u4ee5\u53ca\u8be5\u53d8\u91cf\u7a76\u7adf\u662f\u5bf9\u8c61\u3001\u6307\u9488\u8fd8\u662f\u5f15\u7528\u3001\u6570\u7ec4\u3002<\/li><li>Specifiers<ul><li>storage-class-specifier<\/li><li>type-specifier<\/li><li>function-specifier<\/li><li>friend<\/li><li>typedef<\/li><li>__declspec(extended-decl-modifier-seq)<\/li><\/ul><\/li><li>Initializers<ol><li>Zero initialization<ul><li>\u6570\u503c\u7c7b\u578b\u7684\u53d8\u91cf\u88ab\u521d\u59cb\u5316\u4e3a0(\u6216\u80050.0,\u751a\u81f30.00000000,\u7b49\u7b49)<\/li><li>\u5b57\u7b26\u53d8\u91cf\u88ab\u521d\u59cb\u5316\u4e3a&#8217;\\0&#8242;<\/li><li>\u6307\u9488\u88ab\u521d\u59cb\u5316\u4e3anullptr<\/li><li>\u6570\u7ec4,POD,\u7ed3\u6784\u4f53\u548c\u8054\u5408\u7c7b\u578b\u5c06\u6210\u5458\u521d\u59cb\u4e3a0<\/li><\/ul>\u53d1\u751fZero initialization\u7684\u65f6\u673a\uff1a<ul><li>\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u6240\u6709\u5177\u6709\u9759\u6001\u751f\u547d\u5468\u671f(static duration)\u7684\u6709\u540d\u5b57\u7684\u53d8\u91cf\u3002\u8fd9\u4e9b\u53d8\u91cf\u5728\u7a0d\u540e\u53ef\u80fd\u4f1a\u518d\u88ab\u521d\u59cb\u5316\u4e00\u904d<\/li><li>\u4f7f\u7528<code>{}<\/code>\u521d\u59cb\u5316\u6807\u91cf\u548cPOD\u7c7b\u578b\u65f6\uff0c\u6807\u91cf\u548cPOD\u91cc\u7684\u6210\u5458\u90fd\u7528zero initialization<\/li><li>\u6570\u7ec4\u53ea\u6309\u503c\u521d\u59cb\u5316\u4e86\u4e00\u90e8\u5206\u5143\u7d20\u65f6\uff0c\u5269\u4e0b\u7684\u5143\u7d20\u90fd\u7528zero initialization<\/li><\/ul><\/li><li>Default initialization<br>\u5c31\u662f\u8bf4\u5bf9\u4e8e\u7c7b\u3001\u7ed3\u6784\u4f53\u548c\u8054\u5408\u7c7b\u578b\u4f7f\u7528\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\u521d\u59cb\u5316\u3002\u5f53\u6ca1\u6709\u6307\u5b9a\u521d\u59cb\u5316\u8868\u8fbe\u5f0f\u6216\u8005\u4f7f\u7528new\u5173\u952e\u5b57\u65f6\u5c31\u662f\u7528\u7684\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\u521d\u59cb\u5316<ul><li>\u5e38\u91cf\u53d8\u91cf\u5fc5\u987b\u8981\u6307\u5b9a\u4e00\u4e2a\u521d\u59cb\u5316\u8868\u8fbe\u5f0f\uff0c\u800c\u4e0d\u80fd\u4f7f\u7528\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\u6216\u8005zero initialization<\/li><\/ul><\/li><li>Value initialization<\/li><li>Copy initialization<\/li><li>Direct initialization<\/li><li>List initialization<\/li><li>Aggregate initialization<\/li><li>Reference initialization<\/li><\/ol><\/li><li>\u4f7f\u7528typedef\u548cusing\u7b80\u5316\u590d\u6742\u7c7b\u578b\u7684\u58f0\u660e<\/li><li>Storage classes<ul><li>static<\/li><li>extern<\/li><li>thread_local<\/li><\/ul><\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E5%9F%BA%E7%A1%80%E7%B1%BB%E5%9E%8B\"><span class=\"ez-toc-section\" id=\"%E5%9F%BA%E7%A1%80%E7%B1%BB%E5%9E%8B\"><\/span>\u57fa\u7840\u7c7b\u578b<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E5%86%85%E7%BD%AE%E8%BF%90%E7%AE%97%E7%AC%A6%E5%8F%8A%E5%85%B6%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7\"><span class=\"ez-toc-section\" id=\"%E5%86%85%E7%BD%AE%E8%BF%90%E7%AE%97%E7%AC%A6%E5%8F%8A%E5%85%B6%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7\"><\/span>\u5185\u7f6e\u8fd0\u7b97\u7b26\u53ca\u5176\u4f18\u5148\u7ea7\u548c\u7ed3\u5408\u6027<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E8%A1%A8%E8%BE%BE%E5%BC%8F\"><span class=\"ez-toc-section\" id=\"%E8%A1%A8%E8%BE%BE%E5%BC%8F\"><\/span>\u8868\u8fbe\u5f0f<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E8%AF%AD%E5%8F%A5\"><span class=\"ez-toc-section\" id=\"%E8%AF%AD%E5%8F%A5\"><\/span>\u8bed\u53e5<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4\"><span class=\"ez-toc-section\" id=\"%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4\"><\/span>\u547d\u540d\u7a7a\u95f4<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E6%9E%9A%E4%B8%BE%E7%B1%BB%E5%9E%8B\"><span class=\"ez-toc-section\" id=\"%E6%9E%9A%E4%B8%BE%E7%B1%BB%E5%9E%8B\"><\/span>\u679a\u4e3e\u7c7b\u578b<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E8%81%94%E5%90%88%E7%B1%BB%E5%9E%8B\"><span class=\"ez-toc-section\" id=\"%E8%81%94%E5%90%88%E7%B1%BB%E5%9E%8B\"><\/span>\u8054\u5408\u7c7b\u578b<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E5%87%BD%E6%95%B0\"><span class=\"ez-toc-section\" id=\"%E5%87%BD%E6%95%B0\"><\/span>\u51fd\u6570<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E8%BF%90%E7%AE%97%E7%AC%A6%E9%87%8D%E8%BD%BD\"><span class=\"ez-toc-section\" id=\"%E8%BF%90%E7%AE%97%E7%AC%A6%E9%87%8D%E8%BD%BD\"><\/span>\u8fd0\u7b97\u7b26\u91cd\u8f7d<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E7%B1%BB%E5%92%8C%E7%BB%93%E6%9E%84%E4%BD%93\"><span class=\"ez-toc-section\" id=\"%E7%B1%BB%E5%92%8C%E7%BB%93%E6%9E%84%E4%BD%93\"><\/span>\u7c7b\u548c\u7ed3\u6784\u4f53<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"lambda%E8%A1%A8%E8%BE%BE%E5%BC%8F\"><span class=\"ez-toc-section\" id=\"lambda%E8%A1%A8%E8%BE%BE%E5%BC%8F\"><\/span>lambda\u8868\u8fbe\u5f0f<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E6%95%B0%E7%BB%84\"><span class=\"ez-toc-section\" id=\"%E6%95%B0%E7%BB%84\"><\/span>\u6570\u7ec4<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E5%BC%95%E7%94%A8\"><span class=\"ez-toc-section\" id=\"%E5%BC%95%E7%94%A8\"><\/span>\u5f15\u7528<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E6%8C%87%E9%92%88\"><span class=\"ez-toc-section\" id=\"%E6%8C%87%E9%92%88\"><\/span>\u6307\u9488<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86\"><span class=\"ez-toc-section\" id=\"%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86\"><\/span>\u5f02\u5e38\u5904\u7406<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"trythrow%E5%92%8Ccatch%E8%AF%AD%E5%8F%A5\"><span class=\"ez-toc-section\" id=\"trythrow%E5%92%8Ccatch%E8%AF%AD%E5%8F%A5\"><\/span>try,throw\u548ccatch\u8bed\u53e5<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><code>throw<\/code>\u8868\u8fbe\u5f0f\u7684operand\u53ef\u4ee5\u662f\u4efb\u4f55\u7c7b\u578b\u7684\u5bf9\u8c61\u3002<code>catch<\/code>\u8868\u8fbe\u5f0f\u6839\u636e\u5176\u8981\u6355\u83b7\u7684exception \u6307\u5b9a\u5176operand\u4e3a\u76f8\u5e94\u7684\u7c7b\u578b\u3002\u5982\u679c<code>catch<\/code>\u8868\u8fbe\u5f0f\u60f3\u6355\u83b7\u4efb\u610f\u7c7b\u578b\u7684\u5f02\u5e38\uff0c\u90a3\u4e48\u5c31\u5c06\u5176operand \u5199\u4e3a<code>...<\/code>\u3002\u5982\u679c\u60f3\u5728<code>catch<\/code>\u5757\u91cc\u5c06\u6355\u83b7\u7684\u5f02\u5e38\u91cd\u65b0\u629b\u51fa\uff0c\u90a3\u4e48\u7528\u4e0d\u5e26operand\u7684throw\u8868\u8fbe\u5f0f \u5c31\u53ef\u4ee5\u4e86\u3002\u91cd\u65b0\u629b\u51fa\u7684\u5f02\u5e38\u662f\u88ab\u6355\u83b7\u7684\u540c\u4e00\u4e2a\u5f02\u5e38\uff0c\u800c\u4e0d\u662f\u5176\u62f7\u8d1d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"catch%E8%AF%AD%E5%8F%A5%E7%9A%84%E5%8C%B9%E9%85%8D\"><span class=\"ez-toc-section\" id=\"catch%E8%AF%AD%E5%8F%A5%E7%9A%84%E5%8C%B9%E9%85%8D\"><\/span>catch\u8bed\u53e5\u7684\u5339\u914d<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5982\u679ccatch\u8bed\u53e5\u7684\u53c2\u6570\u662f\u5f15\u7528\uff0c\u90a3\u4e48catch\u8bed\u53e5\u91cc\u7684\u5f02\u5e38\u5bf9\u8c61\u5c31\u6b63\u597d\u662f\u629b\u51fa\u7684\u90a3\u4e2a\u5f02\u5e38\u5bf9\u8c61\uff0c \u5426\u5219\u662f\u5176\u62f7\u8d1d\u3002<\/p>\n\n\n\n<p>\u4e00\u4e2a\u629b\u51fa\u7684\u5f02\u5e38\u53ef\u4ee5\u88ab\u4e0b\u5217catch\u8bed\u53e5\u6355\u83b7\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6ca1\u6709\u6307\u5b9a\u5f02\u5e38\u7c7b\u578b\u7684catch\u8bed\u53e5\uff0c\u5373<code>catch(...)<\/code><\/li><li>\u53c2\u6570\u7c7b\u578b\u548c\u5f02\u5e38\u7c7b\u578b\u76f8\u540c\u7684catch\u8bed\u53e5\uff0c\u7531\u4e8ecatch\u7684\u53c2\u6570\u662f\u539f\u5f02\u5e38\u7684\u62f7\u8d1d\uff0c\u6240\u4ee5const,volatile \u7b49\u4fee\u9970\u7b26\u662f\u88ab\u5ffd\u7565\u7684<\/li><li>\u53c2\u6570\u7c7b\u578b\u6b63\u597d\u662f\u5f02\u5e38\u7c7b\u578b\u7684\u5f15\u7528<\/li><li>\u5e26const\u6216\u8005volatle\u4fee\u9970\u7b26\u7684\u5f02\u5e38\u7c7b\u578b\u7684\u5f15\u7528(a reference to a const or volatile form of the same type as the exception object)<\/li><li>\u53c2\u6570\u7c7b\u578b\u662f\u5f02\u5e38\u7c7b\u578b\u7684\u57fa\u7c7b\u7684catch\u8bed\u53e5\uff0c\u540c\u7406const\u548cvolatile\u4fee\u9970\u7b26\u88ab\u5ffd\u7565<\/li><li>\u53c2\u6570\u7c7b\u578b\u662f\u5f02\u5e38\u7c7b\u578b\u7684\u79ef\u7d2f\u7684\u5f15\u7528&#8230;<\/li><li>\u5e26const\u6216\u8005volatile\u4fee\u9970\u7b26\u7684\u5f02\u5e38\u7c7b\u578b\u7684\u79ef\u7d2f\u7684\u5f15\u7528<\/li><li>\u53c2\u6570\u7c7b\u578b\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u800c\u4e14\u629b\u51fa\u7684\u5f02\u5e38\u6b63\u597d\u4e5f\u662f\u4e00\u4e2a\u6307\u9488\u7c7b\u578b\u800c\u4e14\u8be5\u6307\u9488\u53ef\u4ee5\u901a\u8fc7\u6307\u9488standard pointer conversion rules\u8f6c\u6362\u4e3acatch\u7684\u53c2\u6570\u7c7b\u578b\u6307\u9488<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"stack-unwinding\"><span class=\"ez-toc-section\" id=\"stack_unwinding\"><\/span>stack unwinding<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5f02\u5e38\u4e0d\u88ab\u6355\u83b7\u6216\u8005\u5728stack unwinding\u7684\u8fc7\u7a0b\u4e2d\u51fa\u4e86\u5f02\u5e38\uff0c\u8fd0\u884c\u65f6\u51fd\u6570<code>terminate<\/code>\u4f1a\u88ab\u8c03\u7528\u3002<br>\u5728\u8fdb\u5165catch\u5757\u4e4b\u524d\uff0ctry\u8bed\u53e5\u91cc\u7684\u81ea\u52a8\u53d8\u91cf\u4f1a\u88ab\u9500\u6bc1\u6389(stack unwinding)\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"exception-specification\"><span class=\"ez-toc-section\" id=\"exception_specification\"><\/span>exception specification<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u6307\u5b9a\u51fd\u6570\u4e0d\u629b\u51fa\u4efb\u4f55\u5f02\u5e38\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>noexcept<\/code><\/li><li><code>noexcept(true)<\/code><\/li><li><code>throw()<\/code><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"%E6%9C%AA%E8%A2%AB%E6%8D%95%E8%8E%B7%E7%9A%84%E5%BC%82%E5%B8%B8\"><span class=\"ez-toc-section\" id=\"%E6%9C%AA%E8%A2%AB%E6%8D%95%E8%8E%B7%E7%9A%84%E5%BC%82%E5%B8%B8\"><\/span>\u672a\u88ab\u6355\u83b7\u7684\u5f02\u5e38<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u6709\u672a\u88ab\u6355\u83b7\u7684\u5f02\u5e38\uff0c\u7cfb\u7edf\u4f1a\u8c03\u7528terminate(terminate\u4f1a\u8c03\u7528abort)\u3002\u4e0d \u8fc7\u4e5f\u53ef\u4ee5\u901a\u8fc7<code>set_terminate<\/code>\u8bbe\u7f6eterminate\u8c03\u7528\u6307\u5b9a\u7684\u51fd\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\"><em>\/\/ exceptions_Unhandled_Exceptions.cpp  <\/em>\n<em>\/\/ compile with: \/EHsc  <\/em>\n#include &lt;iostream&gt;  \nusing namespace std;  \nvoid term_func() {  \n   cout &lt;&lt; \"term_func was called by terminate.\" &lt;&lt; endl;  \n   exit( -1 );  \n}  \nint main() {  \n   try  \n   {  \n      set_terminate( term_func );  \n      throw \"Out of memory!\"; <em>\/\/ No catch handler for this exception  <\/em>\n   }  \n   catch( int )  \n   {  \n      cout &lt;&lt; \"Integer exception raised.\" &lt;&lt; endl;  \n   }  \n   return 0;  \n}  \n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E6%96%AD%E8%A8%80%E5%92%8C%E7%94%A8%E6%88%B7%E6%8F%90%E4%BE%9B%E7%9A%84%E4%BF%A1%E6%81%AF\"><span class=\"ez-toc-section\" id=\"%E6%96%AD%E8%A8%80%E5%92%8C%E7%94%A8%E6%88%B7%E6%8F%90%E4%BE%9B%E7%9A%84%E4%BF%A1%E6%81%AF\"><\/span>\u65ad\u8a00\u548c\u7528\u6237\u63d0\u4f9b\u7684\u4fe1\u606f<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E6%A8%A1%E6%9D%BF\"><span class=\"ez-toc-section\" id=\"%E6%A8%A1%E6%9D%BF\"><\/span>\u6a21\u677f<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"event-handling\"><span class=\"ez-toc-section\" id=\"Event_Handling\"><\/span>Event Handling<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"%E4%B8%80%E5%9F%BA%E7%A1%80\"><span class=\"ez-toc-section\" id=\"%E4%B8%80%E3%80%81%E5%9F%BA%E7%A1%80\"><\/span>\u4e00\u3001\u57fa\u7840<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2%E8%BF%90%E7%AE%97%E4%BC%98%E5%85%88%E7%BA%A7\"><span class=\"ez-toc-section\" id=\"2%E8%BF%90%E7%AE%97%E4%BC%98%E5%85%88%E7%BA%A7\"><\/span>2.\u8fd0\u7b97\u4f18\u5148\u7ea7<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u52a0\u3001\u51cf\u3001\u6a21\u8fd0\u7b97\u662f\u4e00\u4e2a\u4f18\u5148\u7ea7\u522b\u7684\u3002<br><a href=\"http:\/\/en.cppreference.com\/w\/cpp\/language\/operator_precedence\">\u5b8c\u6574\u7684\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\u5217\u8868<\/a>\uff0c\u53ef\u4ee5\u770b\u5230<code>,<\/code>\u4f18\u5148\u7ea7\u6700\u4f4e\uff0c\u7ec4\u5408\u8fd0\u7b97\u7b26\u3001\u4e09\u5143\u8fd0\u7b97\u7b26\u3001\u903b\u8f91\u8fd0\u7b97\u7b26\u3001\u4f4d\u8fd0\u7b97\u7b49\u90fd\u633a\u4f4e\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3%E5%87%BD%E6%95%B0%E5%8F%82%E6%95%B0%E9%BB%98%E8%AE%A4%E5%80%BC\"><span class=\"ez-toc-section\" id=\"3%E5%87%BD%E6%95%B0%E5%8F%82%E6%95%B0%E9%BB%98%E8%AE%A4%E5%80%BC\"><\/span>3.\u51fd\u6570\u53c2\u6570\u9ed8\u8ba4\u503c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u53ef\u4ee5\u4e3a\u51fd\u6570\u7684\u53c2\u6570\u6307\u5b9a\u9ed8\u8ba4\u503c\uff0c\u4e0d\u8fc7\u53ea\u80fd\u4ece\u540e\u5f80\u524d\u6307\u5b9a\u3002<br>\u4e0d\u80fd\u5199\u51fa\u4e0b\u9762\u8fd9\u79cd\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">int add(int a, int b=2);\nint add(int a);\n<\/code><\/pre>\n\n\n\n<p>\u5728\u7f16\u8bd1\u7684\u65f6\u5019\u5982\u679c\u6709\u8c03\u7528<code>add(2)<\/code>\uff0c\u90a3\u4e48\u7f16\u8bd1\u5668\u4e0d\u77e5\u9053\u4f60\u5230\u5e95\u8981\u8c03\u7528\u54ea\u4e2a\u51fd\u6570\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4%E5%9C%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E5%88%97%E8%A1%A8%E4%B8%AD%E5%88%9D%E5%A7%8B%E5%8C%96const%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F\"><span class=\"ez-toc-section\" id=\"4%E5%9C%A8%E5%88%9D%E5%A7%8B%E5%8C%96%E5%88%97%E8%A1%A8%E4%B8%AD%E5%88%9D%E5%A7%8B%E5%8C%96const%E6%88%90%E5%91%98%E5%8F%98%E9%87%8F\"><\/span>4.\u5728\u521d\u59cb\u5316\u5217\u8868\u4e2d\u521d\u59cb\u5316const\u6210\u5458\u53d8\u91cf<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>const\u6210\u5458\u53d8\u91cf\u53ea\u80fd\u5728\u6784\u9020\u51fd\u6570\u7684\u521d\u59cb\u5316\u5217\u8868\u4e2d\u8fdb\u884c\u521d\u59cb\u5316<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5%E4%BD%BF%E7%94%A8%E5%8F%8B%E5%85%83%E5%87%BD%E6%95%B0%E6%88%96%E8%80%85friend-class%E6%9D%A5%E8%AE%BF%E9%97%AEprivate%E5%8F%98%E9%87%8F%E6%88%96%E6%88%90%E5%91%98%E5%87%BD%E6%95%B0\"><span class=\"ez-toc-section\" id=\"5%E4%BD%BF%E7%94%A8%E5%8F%8B%E5%85%83%E5%87%BD%E6%95%B0%E6%88%96%E8%80%85friend_class%E6%9D%A5%E8%AE%BF%E9%97%AEprivate%E5%8F%98%E9%87%8F%E6%88%96%E6%88%90%E5%91%98%E5%87%BD%E6%95%B0\"><\/span>5.\u4f7f\u7528\u53cb\u5143\u51fd\u6570\u6216\u8005friend class\u6765\u8bbf\u95eeprivate\u53d8\u91cf\u6216\u6210\u5458\u51fd\u6570<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"6%E4%B8%8D%E8%83%BD%E8%A2%AB%E9%87%8D%E8%BD%BD%E7%9A%84%E8%BF%90%E7%AE%97%E7%AC%A6\"><span class=\"ez-toc-section\" id=\"6%E4%B8%8D%E8%83%BD%E8%A2%AB%E9%87%8D%E8%BD%BD%E7%9A%84%E8%BF%90%E7%AE%97%E7%AC%A6\"><\/span>6.\u4e0d\u80fd\u88ab\u91cd\u8f7d\u7684\u8fd0\u7b97\u7b26<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><code>.<\/code><\/li><li><code>?:<\/code><\/li><li><code>::<\/code><\/li><li><code>.*<\/code>(pointer-to-member operator)<br><a href=\"https:\/\/stackoverflow.com\/a\/6586248\/5357784\">\u5173\u4e8epointer-to-member operator\u7684\u4ecb\u7ecd<\/a><\/li><li><code>sizeof<\/code><\/li><li><code>typeid<\/code><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"7%E5%89%8D%E7%BD%AE%E5%90%8E%E7%BD%AE%E8%87%AA%E5%A2%9E%E5%87%8F%E8%BF%90%E7%AE%97%E7%AC%A6%E7%9A%84%E9%87%8D%E8%BD%BD%E5%A3%B0%E6%98%8E\"><span class=\"ez-toc-section\" id=\"7%E5%89%8D%E7%BD%AE%E5%90%8E%E7%BD%AE%E8%87%AA%E5%A2%9E%E5%87%8F%E8%BF%90%E7%AE%97%E7%AC%A6%E7%9A%84%E9%87%8D%E8%BD%BD%E5%A3%B0%E6%98%8E\"><\/span>7.\u524d\u7f6e\/\u540e\u7f6e\u81ea\u589e\/\u51cf\u8fd0\u7b97\u7b26\u7684\u91cd\u8f7d\u58f0\u660e<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u524d\u7f6e\u7684\u9700\u8981\u4e00\u4e2a\u5f62\u5f0f\u53c2\u6570\uff0c\u540e\u7f6e\u7684\u4e0d\u9700\u8981\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6309\u7167\u5fae\u8f6f\u4e3avisual studio\u51c6\u5907\u7684c++\u6587\u6863\u91cd\u65b0\u5b66\u4e60\u548c\u68b3\u7406\u4e00\u4e0b\u81ea\u5df1\u7684c++\u77e5\u8bc6\uff0c\u53ea\u8003\u8651\u901a\u7528 \u7684\u90e8\u5206\uff0c\u4e0d\u8003\u8651\u53ea\u5728windows\u5e73\u53f0\u4e0a\u63d0\u4f9b\u7684c++\u7279\u6027\u3002\u539f\u6587\u6863\u5730\u5740 Modern C++ Moder&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[8],"class_list":["post-937","post","type-post","status-publish","format-standard","hentry","category-10","tag-c"],"_links":{"self":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/937","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=937"}],"version-history":[{"count":2,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/937\/revisions"}],"predecessor-version":[{"id":940,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/937\/revisions\/940"}],"wp:attachment":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}