{"id":228,"date":"2024-03-28T09:46:04","date_gmt":"2024-03-28T01:46:04","guid":{"rendered":"https:\/\/www.vanforever.com.cn\/?p=228"},"modified":"2024-04-01T21:41:46","modified_gmt":"2024-04-01T13:41:46","slug":"c%e9%9d%a2%e7%bb%8f%e8%ae%b0%e5%bd%95","status":"publish","type":"post","link":"https:\/\/www.vanforever.com.cn\/?p=228","title":{"rendered":"C++\u9762\u7ecf\u8bb0\u5f55"},"content":{"rendered":"<div  class='collapse-block shadow-sm collapse-block-transparent collapsed hide-border-left'><div class='collapse-block-title'><span class='collapse-block-title-inner'>\u67e5\u770b\u7279\u8272\u56fe\u7247<\/span><i class='collapse-icon fa fa-angle-down'><\/i><\/div><div class='collapse-block-body' style='display:none;'><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/pic.vanforever.com.cn\/Vanforever\/20240325\/zac-efron-3840x2160-most-popular-celebs-actor-8481.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large\" data-original=\"https:\/\/pic.vanforever.com.cn\/Vanforever\/20240325\/zac-efron-3840x2160-most-popular-celebs-actor-8481.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" width=\"3840\" height=\"2160\" \/><\/div><\/div><\/div>\n<h1 id=\"c\u9762\u7ecf\u8bb0\u5f55\">C++\u9762\u7ecf\u8bb0\u5f55<\/h1>\n<h2 id=\"const\">const<\/h2>\n<p><strong>\u95ee:\u4e86\u89e3const\u4e48\uff1f\u54ea\u4e9b\u65f6\u5019\u7528\u5230const\uff1f\u4e0e\u5b8f\u5b9a\u4e49\u6709\u4ec0\u4e48\u5dee\u5f02\uff1f<\/strong><\/p>\n<p>\u5f53\u7136\u4e86\u89e3<code>const<\/code>\u3002<code>const<\/code>\u662fC++\u4e2d\u7684\u4e00\u4e2a\u7c7b\u578b\u4fee\u9970\u7b26\uff0c\u5b83\u7528\u4e8e\u6307\u5b9a\u4e00\u4e2a\u53d8\u91cf\u4e3a\u5e38\u91cf\uff0c\u5373\u5176\u503c\u5728\u521d\u59cb\u5316\u540e\u4e0d\u80fd\u88ab\u4fee\u6539\u3002\u4f7f\u7528<code>const<\/code>\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\uff0c\u540c\u65f6\u4e5f\u6709\u52a9\u4e8e\u7f16\u8bd1\u5668\u8fdb\u884c\u66f4\u597d\u7684\u4f18\u5316\u3002<\/p>\n<p>\u5728\u4ee5\u4e0b\u60c5\u51b5\u4e2d\uff0c\u6211\u4eec\u901a\u5e38\u4f1a\u4f7f\u7528<code>const<\/code>\uff1a<\/p>\n<ol start=\"\">\n<li><strong>\u5b9a\u4e49\u5e38\u91cf\u503c<\/strong>\uff1a\u5f53\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e00\u4e9b\u5728\u7a0b\u5e8f\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u4e0d\u4f1a\u6539\u53d8\u7684\u503c\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>const<\/code>\u3002<\/li>\n<\/ol>\n<pre><code class=\"language-cpp\" lang=\"cpp\">const int MAX_SIZE = 100;\n<\/code><\/pre>\n<ol start=\"\">\n<li><strong>\u6307\u9488\u4e0e<code>const<\/code><\/strong>\uff1a\n<ul>\n<li><strong>\u6307\u5411\u5e38\u91cf\u7684\u6307\u9488<\/strong>\uff1a\u6307\u9488\u6307\u5411\u7684\u5185\u5bb9\u4e0d\u80fd\u88ab\u4fee\u6539\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\" lang=\"cpp\">const int *p = &amp;someInt; \/\/ p\u6307\u5411\u7684\u5185\u5bb9\u662f\u5e38\u91cf  \n*p = 5; \/\/ \u9519\u8bef\uff0c\u4e0d\u80fd\u4fee\u6539p\u6307\u5411\u7684\u5185\u5bb9\n<\/code><\/pre>\n<ul>\n<li><strong>\u5e38\u91cf\u6307\u9488<\/strong>\uff1a\u6307\u9488\u672c\u8eab\u4e0d\u80fd\u88ab\u4fee\u6539\uff0c\u5373\u4e0d\u80fd\u6307\u5411\u5176\u4ed6\u5730\u5740\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\" lang=\"cpp\">int *const q = &amp;someInt; \/\/ q\u662f\u5e38\u91cf\u6307\u9488  \nq = &amp;anotherInt; \/\/ \u9519\u8bef\uff0c\u4e0d\u80fd\u4fee\u6539q\u7684\u503c\n<\/code><\/pre>\n<ul>\n<li><strong>\u6307\u5411\u5e38\u91cf\u7684\u5e38\u91cf\u6307\u9488<\/strong>\uff1a\u6307\u9488\u672c\u8eab\u548c\u6307\u5411\u7684\u5185\u5bb9\u90fd\u4e0d\u80fd\u88ab\u4fee\u6539\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\" lang=\"cpp\">const int *const r = &amp;someInt;  \n*r = 5; \/\/ \u9519\u8bef  \nr = &amp;anotherInt; \/\/ \u9519\u8bef\n<\/code><\/pre>\n<\/li>\n<li><strong>\u51fd\u6570\u53c2\u6570<\/strong>\uff1a\u5f53\u4e0d\u5e0c\u671b\u51fd\u6570\u5185\u90e8\u4fee\u6539\u4f20\u5165\u7684\u53c2\u6570\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>const<\/code>\u4fee\u9970\u51fd\u6570\u53c2\u6570\u3002<\/li>\n<\/ol>\n<pre><code class=\"language-cpp\" lang=\"cpp\">void foo(const int &amp;param) {  \n    \/\/ param\u4e0d\u80fd\u88ab\u4fee\u6539  \n}\n<\/code><\/pre>\n<ol start=\"\">\n<li><strong>\u51fd\u6570\u8fd4\u56de\u503c<\/strong>\uff1a\u5f53\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u5bf9\u8c61\uff0c\u4f46\u4e0d\u5e0c\u671b\u8c03\u7528\u8005\u4fee\u6539\u8fd9\u4e2a\u8fd4\u56de\u7684\u5bf9\u8c61\u65f6\uff0c\u53ef\u4ee5\u5728\u51fd\u6570\u58f0\u660e\u4e2d\u4f7f\u7528<code>const<\/code>\u3002<\/li>\n<\/ol>\n<pre><code class=\"language-cpp\" lang=\"cpp\">const MyClass&amp; getMyClass() const;\n<\/code><\/pre>\n<ol start=\"\">\n<li><strong>\u7c7b\u6210\u5458<\/strong>\uff1a\u5728\u7c7b\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>const<\/code>\u6765\u4fee\u9970\u6210\u5458\u53d8\u91cf\u6216\u6210\u5458\u51fd\u6570\uff0c\u8868\u793a\u5b83\u4eec\u4e0d\u53ef\u88ab\u4fee\u6539\u3002<\/li>\n<\/ol>\n<pre><code class=\"language-cpp\" lang=\"cpp\">class MyClass {  \npublic:  \n    const int myConstVar;  \n    void myConstFunc() const;  \n};\n<\/code><\/pre>\n<p><code>const<\/code>\u4e0e\u5b8f\u5b9a\u4e49\u7684\u4e3b\u8981\u5dee\u5f02\u5728\u4e8e\uff1a<\/p>\n<ul>\n<li><strong>\u4f5c\u7528\u57df\u548c\u751f\u547d\u5468\u671f<\/strong>\uff1a<code>const<\/code>\u5b9a\u4e49\u7684\u5e38\u91cf\u5177\u6709\u660e\u786e\u7684\u4f5c\u7528\u57df\u548c\u751f\u547d\u5468\u671f\uff0c\u5b83\u4eec\u9075\u5faaC++\u7684\u4f5c\u7528\u57df\u89c4\u5219\u3002\u800c\u5b8f\u5b9a\u4e49\uff08\u901a\u8fc7<code>#define<\/code>\uff09\u5728\u9884\u5904\u7406\u9636\u6bb5\u5c31\u88ab\u66ff\u6362\uff0c\u6ca1\u6709\u4f5c\u7528\u57df\u548c\u751f\u547d\u5468\u671f\u7684\u6982\u5ff5\uff0c\u53ef\u80fd\u5bfc\u81f4\u610f\u5916\u7684\u540d\u79f0\u51b2\u7a81\u548c\u96be\u4ee5\u8ffd\u8e2a\u7684\u9519\u8bef\u3002<\/li>\n<li><strong>\u7c7b\u578b\u5b89\u5168<\/strong>\uff1a<code>const<\/code>\u5b9a\u4e49\u7684\u5e38\u91cf\u662f\u7c7b\u578b\u5b89\u5168\u7684\uff0c\u7f16\u8bd1\u5668\u4f1a\u68c0\u67e5\u5176\u4f7f\u7528\u662f\u5426\u7b26\u5408\u7c7b\u578b\u89c4\u5219\u3002\u800c\u5b8f\u5b9a\u4e49\u53ea\u662f\u7b80\u5355\u7684\u6587\u672c\u66ff\u6362\uff0c\u4e0d\u8fdb\u884c\u7c7b\u578b\u68c0\u67e5\uff0c\u5bb9\u6613\u5f15\u53d1\u7c7b\u578b\u9519\u8bef\u3002<\/li>\n<li><strong>\u8c03\u8bd5\u548c\u53ef\u7ef4\u62a4\u6027<\/strong>\uff1a\u7531\u4e8e<code>const<\/code>\u662fC++\u8bed\u8a00\u7684\u4e00\u90e8\u5206\uff0c\u5b83\u652f\u6301\u8c03\u8bd5\u5668\u548c\u5176\u4ed6\u5de5\u5177\u8fdb\u884c\u66f4\u597d\u7684\u5206\u6790\u548c\u9519\u8bef\u68c0\u67e5\u3002\u5b8f\u5b9a\u4e49\u5219\u53ef\u80fd\u5bfc\u81f4\u8c03\u8bd5\u56f0\u96be\uff0c\u56e0\u4e3a\u5b83\u4eec\u5728\u7f16\u8bd1\u524d\u5c31\u88ab\u66ff\u6362\uff0c\u4e0d\u4f1a\u5728\u8c03\u8bd5\u4fe1\u606f\u4e2d\u53cd\u6620\u51fa\u6765\u3002<\/li>\n<li><strong>\u5b58\u50a8\u65b9\u5f0f<\/strong>\uff1a<code>const<\/code>\u5b9a\u4e49\u7684\u5e38\u91cf\u901a\u5e38\u4f1a\u88ab\u5206\u914d\u5230\u7a0b\u5e8f\u7684\u9759\u6001\u5b58\u50a8\u533a\uff0c\u800c\u5b8f\u5b9a\u4e49\u53ea\u662f\u6587\u672c\u66ff\u6362\uff0c\u4e0d\u5360\u7528\u5b58\u50a8\u7a7a\u95f4\u3002<\/li>\n<\/ul>\n<p>\u603b\u7684\u6765\u8bf4\uff0c<code>const<\/code>\u63d0\u4f9b\u4e86\u4e00\u79cd\u66f4\u5b89\u5168\u3001\u66f4\u6613\u4e8e\u7ef4\u62a4\u7684\u65b9\u5f0f\u6765\u5b9a\u4e49\u548c\u4f7f\u7528\u5e38\u91cf\uff0c\u800c\u5b8f\u5b9a\u4e49\u5219\u66f4\u591a\u5730\u7528\u4e8e\u7b80\u5355\u7684\u6587\u672c\u66ff\u6362\u548c\u6761\u4ef6\u7f16\u8bd1\u7b49\u573a\u666f\u3002\u5728\u73b0\u4ee3C++\u7f16\u7a0b\u4e2d\uff0c\u901a\u5e38\u63a8\u8350\u4f7f\u7528<code>const<\/code>\u548c<code>constexpr<\/code>\u6765\u5b9a\u4e49\u5e38\u91cf\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u5b8f\u5b9a\u4e49\u3002<\/p>\n<p><strong>\u95ee:\u8bf7\u518d\u89e3\u91ca\u4e0b\u8fd9\u53e5\u8bdd const\u5b9a\u4e49\u7684\u5e38\u91cf\u5177\u6709\u660e\u786e\u7684\u4f5c\u7528\u57df\u548c\u751f\u547d\u5468\u671f\uff0c\u5b83\u4eec\u9075\u5faaC++\u7684\u4f5c\u7528\u57df\u89c4\u5219\u3002\u800c\u5b8f\u5b9a\u4e49\uff08\u901a\u8fc7#define\uff09\u5728\u9884\u5904\u7406\u9636\u6bb5\u5c31\u88ab\u66ff\u6362\uff0c\u6ca1\u6709\u4f5c\u7528\u57df\u548c\u751f\u547d\u5468\u671f\u7684\u6982\u5ff5\uff0c\u53ef\u80fd\u5bfc\u81f4\u610f\u5916\u7684\u540d\u79f0\u51b2\u7a81\u548c\u96be\u4ee5\u8ffd\u8e2a\u7684\u9519\u8bef\u3002<\/strong><\/p>\n<p>\u597d\u7684\uff0c\u6211\u4f1a\u8fdb\u4e00\u6b65\u89e3\u91ca\u8fd9\u53e5\u8bdd\u7684\u542b\u4e49\u3002<\/p>\n<p>\u9996\u5148\uff0c\u8ba9\u6211\u4eec\u8c08\u8c08<code>const<\/code>\u5b9a\u4e49\u7684\u5e38\u91cf\u3002\u5728C++\u4e2d\uff0c\u5f53\u4f60\u4f7f\u7528<code>const<\/code>\u5173\u952e\u5b57\u5b9a\u4e49\u4e00\u4e2a\u5e38\u91cf\u65f6\uff0c\u8fd9\u4e2a\u5e38\u91cf\u4f1a\u6709\u4e00\u4e2a\u660e\u786e\u7684\u4f5c\u7528\u57df\uff0c\u5373\u5b83\u5728\u54ea\u91cc\u662f\u53ef\u89c1\u7684\u3002\u8fd9\u901a\u5e38\u662f\u7531\u5b83\u58f0\u660e\u7684\u4f4d\u7f6e\uff08\u6bd4\u5982\u5728\u51fd\u6570\u5185\u90e8\u3001\u7c7b\u5185\u90e8\u3001\u5168\u5c40\u4f5c\u7528\u57df\u7b49\uff09\u51b3\u5b9a\u7684\u3002\u540c\u65f6\uff0c\u5e38\u91cf\u4e5f\u6709\u4e00\u4e2a\u751f\u547d\u5468\u671f\uff0c\u5b83\u901a\u5e38\u4e0e\u5305\u542b\u5b83\u7684\u4ee3\u7801\u5757\u7684\u751f\u547d\u5468\u671f\u76f8\u5173\u8054\u3002\u4e00\u65e6\u8d85\u51fa\u8fd9\u4e2a\u4f5c\u7528\u57df\u6216\u751f\u547d\u5468\u671f\uff0c\u8be5\u5e38\u91cf\u5c31\u4e0d\u518d\u53ef\u8bbf\u95ee\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">void someFunction() {  \n    const int localConst = 10; \/\/ \u5c40\u90e8\u5e38\u91cf\uff0c\u4f5c\u7528\u57df\u548c\u751f\u547d\u5468\u671f\u9650\u4e8e\u8fd9\u4e2a\u51fd\u6570  \n}  \n  \nint main() {  \n    const int globalConst = 20; \/\/ \u5168\u5c40\u5e38\u91cf\uff0c\u4f5c\u7528\u57df\u662f\u6574\u4e2a\u7a0b\u5e8f\uff0c\u751f\u547d\u5468\u671f\u901a\u5e38\u4e5f\u662f\u6574\u4e2a\u7a0b\u5e8f\u6267\u884c\u671f\u95f4  \n    return 0;  \n}\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>localConst<\/code>\u7684\u4f5c\u7528\u57df\u548c\u751f\u547d\u5468\u671f\u4ec5\u9650\u4e8e<code>someFunction<\/code>\u51fd\u6570\u5185\u90e8\uff0c\u800c<code>globalConst<\/code>\u7684\u4f5c\u7528\u57df\u662f\u6574\u4e2a\u7a0b\u5e8f\uff0c\u751f\u547d\u5468\u671f\u4e5f\u662f\u6574\u4e2a\u7a0b\u5e8f\u6267\u884c\u671f\u95f4\u3002<\/p>\n<p>\u7136\u800c\uff0c\u5b8f\u5b9a\u4e49\u662f\u901a\u8fc7\u9884\u5904\u7406\u5668\u6307\u4ee4<code>#define<\/code>\u6765\u521b\u5efa\u7684\uff0c\u5b83\u4eec\u5728\u7f16\u8bd1\u8fc7\u7a0b\u7684\u9884\u5904\u7406\u9636\u6bb5\u5c31\u88ab\u6587\u672c\u66ff\u6362\u3002\u8fd9\u610f\u5473\u7740\u5b8f\u6ca1\u6709\u4f5c\u7528\u57df\u548c\u751f\u547d\u5468\u671f\u7684\u6982\u5ff5\uff0c\u5b83\u4eec\u5728\u4ee3\u7801\u4e2d\u88ab\u66ff\u6362\u7684\u4f4d\u7f6e\u53d6\u51b3\u4e8e\u5b8f\u7684\u540d\u5b57\u5728\u6e90\u4ee3\u7801\u4e2d\u51fa\u73b0\u7684\u4f4d\u7f6e\uff0c\u800c\u4e0d\u662f\u5b9a\u4e49\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">#define PI 3.14159  \n  \nvoid usePi() {  \n    double area = PI * radius * radius; \/\/ PI\u5728\u8fd9\u91cc\u88ab\u66ff\u6362\u4e3a3.14159  \n}  \n  \nint main() {  \n    double circumference = 2 * PI * radius; \/\/ PI\u540c\u6837\u5728\u8fd9\u91cc\u88ab\u66ff\u6362  \n    return 0;  \n}\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4e0d\u8bba<code>PI<\/code>\u5728\u54ea\u91cc\u88ab\u4f7f\u7528\uff0c\u9884\u5904\u7406\u5668\u90fd\u4f1a\u5c06\u5176\u66ff\u6362\u4e3a<code>3.14159<\/code>\u3002\u56e0\u6b64\uff0c\u5982\u679c\u4f60\u5728\u4e0d\u540c\u7684\u5934\u6587\u4ef6\u4e2d\u6216\u4e0d\u540c\u7684\u5730\u65b9\u5b9a\u4e49\u4e86\u540c\u540d\u7684\u5b8f\uff0c\u5c31\u53ef\u80fd\u5bfc\u81f4\u540d\u79f0\u51b2\u7a81\uff0c\u56e0\u4e3a\u9884\u5904\u7406\u5668\u53ea\u662f\u7b80\u5355\u5730\u66ff\u6362\u6587\u672c\uff0c\u800c\u4e0d\u8003\u8651\u4f5c\u7528\u57df\u6216\u751f\u547d\u5468\u671f\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u7531\u4e8e\u5b8f\u53ea\u662f\u6587\u672c\u66ff\u6362\uff0c\u5b83\u4eec\u4e0d\u4f1a\u53d7\u5230C++\u7684\u7c7b\u578b\u7cfb\u7edf\u7684\u7ea6\u675f\u3002\u8fd9\u53ef\u80fd\u5bfc\u81f4\u96be\u4ee5\u8ffd\u8e2a\u7684\u9519\u8bef\uff0c\u56e0\u4e3a\u7f16\u8bd1\u5668\u4e0d\u4f1a\u68c0\u67e5\u5b8f\u7684\u4f7f\u7528\u662f\u5426\u7b26\u5408\u9884\u671f\u7684\u7c7b\u578b\u3002<\/p>\n<p>\u603b\u7ed3\u6765\u8bf4\uff0c<code>const<\/code>\u5b9a\u4e49\u7684\u5e38\u91cf\u5177\u6709\u660e\u786e\u7684\u4f5c\u7528\u57df\u548c\u751f\u547d\u5468\u671f\uff0c\u9075\u5faaC++\u7684\u4f5c\u7528\u57df\u89c4\u5219\uff0c\u63d0\u4f9b\u4e86\u7c7b\u578b\u5b89\u5168\u548c\u66f4\u597d\u7684\u8c03\u8bd5\u652f\u6301\u3002\u800c\u5b8f\u5b9a\u4e49\u5728\u9884\u5904\u7406\u9636\u6bb5\u5c31\u88ab\u66ff\u6362\uff0c\u6ca1\u6709\u4f5c\u7528\u57df\u548c\u751f\u547d\u5468\u671f\u7684\u6982\u5ff5\uff0c\u53ef\u80fd\u5bfc\u81f4\u610f\u5916\u7684\u540d\u79f0\u51b2\u7a81\u548c\u96be\u4ee5\u8ffd\u8e2a\u7684\u7c7b\u578b\u9519\u8bef\u3002\u56e0\u6b64\uff0c\u5728\u73b0\u4ee3C++\u7f16\u7a0b\u4e2d\uff0c\u63a8\u8350\u4f7f\u7528<code>const<\/code>\u548c<code>constexpr<\/code>\u6765\u5b9a\u4e49\u5e38\u91cf\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u5b8f\u5b9a\u4e49\uff0c\u9664\u975e\u5728\u7279\u5b9a\u60c5\u51b5\u4e0b\u5b8f\u5b9a\u4e49\u786e\u5b9e\u63d0\u4f9b\u4e86\u5fc5\u8981\u7684\u7075\u6d3b\u6027\u6216\u6027\u80fd\u4f18\u52bf\u3002<\/p>\n<p><strong>\u95ee:\u9876\u5c42const\u548c\u5e95\u5c42const\u7684\u533a\u522b<\/strong><\/p>\n<p><strong>\u53ea\u9700\u8981\u8bb0\u4f4f\uff0c\u5728\u62f7\u8d1d\u65f6\uff0c\u65e2\u8981\u5224\u65ad\u6307\u9488\u672c\u8eab\u7684const\u8f6c\u6362\u662f\u5426\u5408\u6cd5\uff0c\u53c8\u8981\u5224\u65ad\u6307\u9488\u6240\u6307\u5bf9\u8c61\u7684const\u8f6c\u6362\u662f\u5426\u5408\u6cd5\u3002<\/strong><\/p>\n<ol start=\"\">\n<li><strong>\u5bf9\u4e8e\u6307\u9488\u672c\u8eab\u662f\u5426\u662f\u5e38\u91cf\u3001\u5176\u6240\u6307\u5bf9\u8c61\u662f\u5426\u662f\u5e38\u91cf\uff0c\u6309\u7167\u4ece\u53f3\u5f80\u5de6\u7684\u8bfb\u6cd5\u6765\u5224\u65ad\uff1a<\/strong><\/li>\n<\/ol>\n<pre><code class=\"language-cpp\" lang=\"cpp\">int a = 0; \nconst int *const p= a; \/\/\u7b2c\u4e8c\u4e2aconst\u5176\u5b9e\u662fconst p\uff0c\u8868\u793ap\u8fd9\u4e2a\u6307\u9488\u672c\u8eab\u662f\u5e38\u91cf\uff0c\u5373\u5176\u4e2d\u5b58\u653e\u7684\u5730\u5740\u4e0d\u80fd\u53d8\u3002\n\/\/\u7b2c\u4e00\u4e2aconst\uff0c\u5176\u5b9e\u662f const *p\uff0c \u8868\u793a*p\u4e0d\u53d8\uff0c\u5373\u5176\u6307\u5411\u7684\u5bf9\u8c61\u4e0d\u53d8\u3002\n<\/code><\/pre>\n<ol start=\"2\">\n<li><strong>\u4e00\u822c\u6765\u8bf4\uff0c\u975e\u5e38\u91cf\u53ef\u4ee5\u8f6c\u6362\u6210\u5e38\u91cf\uff0c\u53cd\u4e4b\u5219\u4e0d\u884c<\/strong><\/li>\n<\/ol>\n<p><strong>\u57fa\u4e8e\u8fd9\u4e24\u70b9\uff0c\u5c31\u80fd\u89e3\u51b3\u5173\u4e8econst\u62f7\u8d1d\u662f\u5426\u5408\u6cd5\u7684\u95ee\u9898\u4e86\u3002<\/strong><\/p>\n<ol start=\"\">\n<li>\u5148\u770bc++ primer\u91cc\u7684\u539f\u6587\uff1a<\/li>\n<\/ol>\n<blockquote><p>\u5982\u524d\u6240\u8ff0\uff0c\u6307\u9488\u672c\u8eab\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5b83\u53c8\u53ef\u4ee5\u6307\u5411\u53e6\u5916\u4e00\u4e2a\u5bf9\u8c61\u3002\u56e0\u6b64\uff0c\u6307\u9488\u672c\u8eab\u662f\u4e0d\u662f\u5e38\u91cf\u4ee5\u53ca\u6307\u9488\u6240\u6307\u7684\u662f\u4e0d\u662f\u4e00\u4e2a\u5e38\u91cf\u5c31\u662f\u4e24\u4e2a\u76f8\u4e92\u72ec\u7acb\u7684\u95ee\u9898\u3002\u7528\u540d\u8bcd<strong>\u9876\u5c42 const \u8868\u793a\u6307\u9488\u672c\u8eab\u662f\u4e2a\u5e38\u91cf<\/strong>\uff0c\u800c\u7528\u540d\u8bcd<strong>\u5e95\u5c42 const\uff08low-level const\uff09\u8868\u793a\u6307\u9488\u6240\u6307\u7684\u5bf9\u8c61\u662f\u4e00\u4e2a\u5e38\u91cf<\/strong>\u3002<br \/>\n\u66f4\u4e00\u822c\u7684\uff0c<strong>\u9876\u5c42 const \u53ef\u4ee5\u8868\u793a\u4efb\u610f\u7684\u5bf9\u8c61\u662f\u5e38\u91cf<\/strong>\uff0c\u8fd9\u4e00\u70b9\u5bf9\u4efb\u4f55\u6570\u636e\u7c7b\u578b\u90fd\u9002\u7528\uff0c\u5982\u7b97\u672f\u7c7b\u578b\u3001\u7c7b\u3001\u6307\u9488\u7b49\u3002<strong>\u5e95\u5c42 const \u5219\u4e0e\u6307\u9488\u548c\u5f15\u7528\u7b49\u590d\u5408\u7c7b\u578b\u7684\u57fa\u672c\u7c7b\u578b\u90e8\u5206\u6709\u5173<\/strong>\u3002\u6bd4\u8f83\u7279\u6b8a\u7684\u662f\uff0c\u6307\u9488\u7c7b\u578b\u65e2\u53ef\u4ee5\u662f\u9876\u5c42 const \u4e5f\u53ef\u4ee5\u662f\u5e95\u5c42const\uff0c\u8fd9\u4e00\u70b9\u548c\u5176\u4ed6\u7c7b\u578b\u76f8\u6bd4\u533a\u522b\u660e\u663e\u2236<\/p><\/blockquote>\n<p><strong>\u5bf9\u4e8e\u6307\u9488\u672c\u8eab\u662f\u5426\u662f\u5e38\u91cf\u3001\u5176\u6240\u6307\u5bf9\u8c61\u662f\u5426\u662f\u5e38\u91cf\uff0c\u6309\u7167\u4ece\u53f3\u5f80\u5de6\u7684\u8bfb\u6cd5\u6765\u5224\u65ad\uff1a<\/strong><\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">int a = 0; \nconst int *const p= a; \/\/\u7b2c\u4e8c\u4e2aconst\u5176\u5b9e\u662fconst p\uff0c\u8868\u793ap\u8fd9\u4e2a\u6307\u9488\u672c\u8eab\u662f\u5e38\u91cf\uff0c\u5373\u5176\u4e2d\u5b58\u653e\u7684\u5730\u5740\u4e0d\u80fd\u53d8\u3002\n\/\/\u7b2c\u4e00\u4e2aconst\uff0c\u5176\u5b9e\u662f const *p\uff0c \u8868\u793a*p\u4e0d\u53d8\uff0c\u5373\u5176\u6307\u5411\u7684\u5bf9\u8c61\u4e0d\u53d8\u3002\n<\/code><\/pre>\n<p><strong>\u6240\u4ee5\u53ef\u4ee5\u8ba4\u4e3a\u5728\u7b2c\u4e00\u4e2aconst\u662f\u5e95\u5c42const\uff0c\u7b2c\u4e8c\u4e2aconst\u662f\u9876\u5c42const.<\/strong><\/p>\n<p>2.\u4e66\u4e2d\u5b9a\u4e49\u9876\u5c42\u548c\u5e95\u5c42\uff0c\u4e3b\u8981\u7528\u6765\u5224\u65ad\u62f7\u8d1d\u8fc7\u7a0b\u662f\u5426\u5408\u6cd5\uff1a<\/p>\n<blockquote><p>\u5f53\u6267\u884c\u5bf9\u8c61\u7684\u62f7\u8d1d\u64cd\u4f5c\u65f6\uff0c\u5e38\u91cf\u662f\u9876\u5c42const\u8fd8\u662f\u5e95\u5c42const \u533a\u522b\u660e\u663e\u3002<br \/>\n<strong>\u5176\u4e2d\uff0c\u9876\u5c42const\u4e0d\u53d7\u4ec0\u4e48\u5f71\u54cd\u2236<\/strong><br \/>\n\u53e6\u4e00\u65b9\u9762\uff0c<strong>\u5e95\u5c42 const \u7684\u9650\u5236\u5374\u4e0d\u80fd\u5ffd\u89c6\u3002<\/strong>\u5f53\u6267\u884c\u5bf9\u8c61\u7684\u62f7\u8d1d\u64cd\u4f5c\u65f6\uff0c\u62f7\u5165\u548c\u62f7\u51fa\u7684\u5bf9\u8c61\u5fc5\u987b\u5177\u6709\u76f8\u540c\u7684\u5e95\u5c42 const \u8d44\u683c\uff0c\u6216\u8005\u4e24\u4e2a\u5bf9\u8c61\u7684\u6570\u636e\u7c7b\u578b\u5fc5\u987b\u80fd\u591f\u8f6c\u6362\u3002<br \/>\n<strong>\u4e00\u822c\u6765\u8bf4\uff0c\u975e\u5e38\u91cf\u53ef\u4ee5\u8f6c\u6362\u6210\u5e38\u91cf\uff0c\u53cd\u4e4b\u5219\u4e0d\u884c\u2236<\/strong><\/p><\/blockquote>\n<p>\u53ef\u4ee5\u89e3\u91ca\u4e3a\uff0c\u9876\u5c42const\u5728\u62f7\u8d1d\u7684\u65f6\u5019\uff0c\u56e0\u4e3a\u5b83\u672c\u8eab\u5c31\u662f\u5e38\u91cf\uff0c\u53ea\u9700\u8981\u8003\u8651\u5b83\u672c\u8eab\u62f7\u51fa\u548c\u62f7\u5165\u5bf9\u8c61\u4e4b\u95f4\u7c7b\u578b\u662f\u5426\u76f8\u540c\uff1b\u800c\u5e95\u5c42const\u53ea\u662f\u4ee3\u8868\u5b83\u6240\u6307\u5bf9\u8c61\u65f6\u5e38\u91cf\uff0c\u6240\u4ee5\u5728\u62f7\u8d1d\u5b83\u7684\u65f6\u5019\u8fd8\u8981\u8003\u8651\u5b83\u6307\u5411\u7684\u5bf9\u8c61\u662f\u5426\u662f\u76f8\u540c\u7c7b\u578b\u3002<\/p>\n<p>\u6240\u4ee5\u6211\u8ba4\u4e3a\u9876\u5c42\u3001\u5e95\u5c42\u7684\u6982\u5ff5\u662f\u7528\u4e8e\u5224\u65ad\u5728\u62f7\u8d1d\u65f6\u5e94\u8be5\u8003\u8651\u54ea\u4e2a\u5c42\u6b21\u7c7b\u578b\u4fdd\u6301\u4e00\u76f4\u7684\u95ee\u9898\u3002<\/p>\n<p>\u800c\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u672c\u8d28\uff0c\u5176\u5b9e\u5c31\u662f\u5224\u65ad\u662f\u5e38\u91cf\u6307\u9488\uff0c\u8fd8\u662f\u5e38\u91cf\u7684\u6307\u9488\u3002<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">int i = 0;\nconst int ci = 42;  \/\/\u8fd9\u662f\u4e00\u4e2a\u9876\u5c42const\uff0c\u57fa\u4e8e\u9876\u5c42const\u5b9a\u4e49+\u201c\u9876\u5c42 const \u53ef\u4ee5\u8868\u793a\u4efb\u610f\u7684\u5bf9\u8c61\u662f\u5e38\u91cf\u201d\nconst int *p2 = &amp;ci; \/\/\u8fd9\u662f\u4e00\u4e2a\u5e95\u5c42const\nconst int *const p3 = p2; \/\/\u9760\u53f3\u7684\u662f\u9876\u5c42\uff0c\u9760\u5de6\u7684\u662f\u5e95\u5c42\n\ni = ci; \/\/\u6b63\u786e\uff0cci\u662f\u4e00\u4e2a\u9876\u5c42\uff0c\u53ea\u9700\u8981\u8003\u8651\u5b83\u672c\u8eab\u548ci\u7c7b\u578b\u662f\u5426\u5bf9\u7684\u4e0a\np2 = p3; \/\/\u6b63\u786e\uff0c\u5bf9\u4e8e\u5e95\u5c42\u90e8\u5206\uff0c\u8003\u8651\u5b83\u4eec\u6240\u6307\u7684\u5bf9\u8c61\uff0cp2\u6307\u5411\u5e38\u91cf\uff0cp3\u6307\u5411\u975e\u5e38\u91cf\u3002\u5bf9\u4e8e\u9876\u5c42\u90e8\u5206\uff0cp3\u662f\u9876\u5c42\uff0c\u6240\u4ee5\u4e0d\u5f71\u54cd\u3002\n\nint *p = p3; \/\/\u9519\u8bef\uff0c\u5e95\u5c42\u90e8\u5206\uff0cp3\u6709\u5e95\u5c42\u800cp\u6ca1\u6709\uff0cp3\u6307\u5411\u5e38\u91cf\uff0cp\u6307\u5411\u975e\u5e38\u91cf\uff0c\u90a3\u4e48\u7a0b\u5e8f\u53ef\u4ee5\u8bd5\u56fe\u901a\u8fc7p\u53bb\u6539\u53d8\u4e00\u4e2a\u5e38\u91cf\uff0c\u6240\u4ee5\u662f\u9519\u8bef\u7684\u3002\np2 = p3\uff1b \/\/\u6b63\u786e, \u4e24\u4e2a\u90fd\u662f\u5e95\u5c42\uff0c\u5373\u6307\u5411\u7684\u90fd\u662f\u5e38\u91cf\u3002\np2 = &amp;i; \/\/\u6b63\u786e\uff0c\u5e95\u5c42\u90e8\u5206\uff1ap2\u6307\u5411\u5e38\u91cf\uff0c\u4f46\u662fint i\u662f\u53ef\u4ee5\u8f6c\u6362\u6210\u5e38\u91cf\u7684\u3002\nint &amp;r = ci; \/\/\u9519\u8bef\uff0c\u56e0\u4e3a\u975e\u5e38\u91cf\u7684\u5f15\u7528r\u4f1a\u8bd5\u56fe\u6539\u53d8\u5e38\u91cfci\u7684\u503c\u3002\nconst int &amp;r2 =i; \/\/\u6b63\u786e\uff0c\u7528\u4e8e\u58f0\u660e\u5f15\u7528\u7684\u90fd\u662f\u5e95\u5c42const\uff0cint i\u53ef\u4ee5\u8f6c\u6362\u6210\u5e38\u91cf\u3002\n<\/code><\/pre>\n<h2 id=\"reference\u548cpointer\">reference\u548cpointer<\/h2>\n<p><strong>\u95ee:reference\u548cpointer\u7684\u533a\u522b\uff1f\u54ea\u4e9b\u60c5\u51b5\u4f7f\u7528pointer\uff1f<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u5b83\u4eec\u7684\u4e3b\u8981\u529f\u80fd\u90fd\u662f\u7528\u6765\u95f4\u63a5\u8bbf\u95ee\u53e6\u4e00\u4e2a\u5bf9\u8c61\u7684\u503c\u3002\u4f46\u662f\uff0creference\uff08\u5f15\u7528\uff09\u5728\u58f0\u660e\u65f6\u5fc5\u987b\u88ab\u521d\u59cb\u5316\uff0c\u4e00\u65e6\u521d\u59cb\u5316\u540e\u5c31\u4e0d\u80fd\u518d\u6307\u5411\u5176\u4ed6\u5bf9\u8c61\uff0c\u53ef\u4ee5\u5c06\u5176\u770b\u4f5c\u662f\u5bf9\u8c61\u7684\u522b\u540d\u3002\u800cpointer\uff08\u6307\u9488\uff09\u5219\u53ef\u4ee5\u5728\u4efb\u4f55\u65f6\u5019\u6307\u5411\u4e0d\u540c\u7684\u5bf9\u8c61\uff0c\u800c\u4e14\u5728\u58f0\u660e\u65f6\u53ef\u4ee5\u9009\u62e9\u4e0d\u521d\u59cb\u5316\uff0c\u5373\u53ef\u4ee5\u4e3a\u7a7a\u3002<\/p>\n<p>\u5176\u6b21\uff0c\u4ece\u5185\u5b58\u5b58\u50a8\u5f62\u5f0f\u6765\u770b\uff0c\u5f15\u7528\u4e0d\u9700\u8981\u89e3\u5f15\u7528\u64cd\u4f5c\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\uff0c\u800c\u6307\u9488\u5219\u9700\u8981\u4f7f\u7528\u661f\u53f7\u64cd\u4f5c\u7b26\u8fdb\u884c\u89e3\u5f15\u7528\u3002<\/p>\n<p>\u518d\u8005\uff0c\u4ece\u4f7f\u7528\u573a\u666f\u6765\u770b\uff0c\u5f15\u7528\u4e3b\u8981\u7528\u4e8e\u4f5c\u4e3a\u51fd\u6570\u7684\u53c2\u6570\u548c\u8fd4\u56de\u503c\uff0c\u800c\u6307\u9488\u5219\u66f4\u591a\u5730\u7528\u4e8e\u52a8\u6001\u5185\u5b58\u5206\u914d\u3001\u94fe\u8868\u7b49\u6570\u636e\u7ed3\u6784\u4ee5\u53ca\u67d0\u4e9b\u9700\u8981\u7075\u6d3b\u6539\u53d8\u6307\u5411\u5bf9\u8c61\u7684\u573a\u666f\u3002<\/p>\n<p>\u81f3\u4e8e\u54ea\u4e9b\u60c5\u51b5\u4f7f\u7528pointer\uff0c\u6211\u8ba4\u4e3a\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u79cd\u60c5\u51b5\uff1a<\/p>\n<ol>\n<li>\u5f53\u9700\u8981\u52a8\u6001\u5206\u914d\u5185\u5b58\u65f6\uff0c\u901a\u5e38\u4f1a\u4f7f\u7528\u6307\u9488\u6765\u6307\u5411\u52a8\u6001\u5206\u914d\u7684\u5185\u5b58\u7a7a\u95f4\u3002<\/li>\n<li>\u5728\u5904\u7406\u94fe\u8868\u3001\u6811\u7b49\u590d\u6742\u6570\u636e\u7ed3\u6784\u65f6\uff0c\u6307\u9488\u53ef\u4ee5\u65b9\u4fbf\u5730\u6307\u5411\u94fe\u8868\u8282\u70b9\u6216\u6811\u7684\u8282\u70b9\uff0c\u5b9e\u73b0\u6570\u636e\u7684\u904d\u5386\u548c\u64cd\u4f5c\u3002<\/li>\n<li>\u5f53\u9700\u8981\u7075\u6d3b\u6539\u53d8\u6307\u5411\u5bf9\u8c61\u65f6\uff0c\u6bd4\u5982\u4ea4\u6362\u4e24\u4e2a\u53d8\u91cf\u7684\u503c\uff0c\u6216\u8005\u5b9e\u73b0\u51fd\u6570\u7684\u591a\u8fd4\u56de\u503c\u529f\u80fd\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u6307\u9488\u3002<\/li>\n<\/ol>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u4f7f\u7528\u6307\u9488\u65f6\u9700\u8981\u7279\u522b\u5c0f\u5fc3\uff0c\u907f\u514d\u51fa\u73b0\u91ce\u6307\u9488\u3001\u7a7a\u6307\u9488\u7b49\u95ee\u9898\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u6211\u8ba4\u4e3a\u7406\u89e3reference\u548cpointer\u7684\u5e95\u5c42\u5b9e\u73b0\u673a\u5236\u4e5f\u5f88\u91cd\u8981\uff0c\u8fd9\u6709\u52a9\u4e8e\u6211\u4eec\u66f4\u597d\u5730\u4f7f\u7528\u5b83\u4eec\u3002\u6bd4\u5982\uff0c\u5f15\u7528\u5728\u5e95\u5c42\u662f\u901a\u8fc7\u6307\u9488\u6765\u5b9e\u73b0\u7684\uff0c\u4f46\u662f\u5b83\u4eec\u5728\u4f7f\u7528\u65b9\u5f0f\u548c\u8bed\u4e49\u4e0a\u6709\u5f88\u5927\u7684\u533a\u522b\u3002<\/p>\n<h2 id=\"inline\">inline<\/h2>\n<p><strong>\u95ee:inline\u7684\u4f18\u52a3<\/strong><\/p>\n<p>\u5f53\u7136\u53ef\u4ee5\u3002\u4e0b\u9762\u6211\u5c06\u901a\u8fc7\u4e00\u4e2a\u5177\u4f53\u7684\u4f8b\u5b50\u6765\u89e3\u91cainline\u51fd\u6570\u7684\u4f18\u52a3\u3002<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u7b80\u5355\u7684\u7c7b<code>Calculator<\/code>\uff0c\u5b83\u6709\u4e00\u4e2a\u6210\u5458\u51fd\u6570<code>add<\/code>\u7528\u4e8e\u8ba1\u7b97\u4e24\u4e2a\u6574\u6570\u7684\u548c\u3002<\/p>\n<p>\u4e0d\u4f7f\u7528inline\u7684\u60c5\u51b5\uff1a<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">class Calculator {  \npublic:  \n    int add(int a, int b) {  \n        return a + b;  \n    }  \n};  \n  \n\/\/ \u5728\u67d0\u4e2a\u5730\u65b9\u4f7f\u7528\u8fd9\u4e2a\u7c7b  \nCalculator calc;  \nint sum = calc.add(2, 3);\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6bcf\u6b21\u8c03\u7528<code>add<\/code>\u51fd\u6570\u65f6\uff0c\u90fd\u4f1a\u53d1\u751f\u51fd\u6570\u8c03\u7528\u5f00\u9500\uff0c\u5305\u62ec\u5c06\u53c2\u6570\u538b\u5165\u6808\u4e2d\u3001\u8df3\u8f6c\u5230\u51fd\u6570\u5b9e\u73b0\u4ee3\u7801\u3001\u6267\u884c\u51fd\u6570\u4ee3\u7801\u3001\u8fd4\u56de\u7ed3\u679c\u5e76\u6062\u590d\u6808\u72b6\u6001\u3002\u5982\u679c<code>add<\/code>\u51fd\u6570\u88ab\u9891\u7e41\u8c03\u7528\uff0c\u8fd9\u4e9b\u5f00\u9500\u53ef\u80fd\u4f1a\u53d8\u5f97\u663e\u8457\u3002<\/p>\n<p>\u4f7f\u7528inline\u7684\u60c5\u51b5\uff1a<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">class Calculator {  \npublic:  \n    inline int add(int a, int b) {  \n        return a + b;  \n    }  \n};  \n  \n\/\/ \u5728\u67d0\u4e2a\u5730\u65b9\u4f7f\u7528\u8fd9\u4e2a\u7c7b  \nCalculator calc;  \nint sum = calc.add(2, 3);\n<\/code><\/pre>\n<p>\u901a\u8fc7\u5c06<code>add<\/code>\u51fd\u6570\u58f0\u660e\u4e3ainline\uff0c\u6211\u4eec\u8bf7\u6c42\u7f16\u8bd1\u5668\u5728\u8c03\u7528<code>add<\/code>\u51fd\u6570\u7684\u5730\u65b9\u76f4\u63a5\u63d2\u5165\u51fd\u6570\u7684\u4ee3\u7801\uff0c\u800c\u4e0d\u662f\u8fdb\u884c\u5e38\u89c4\u7684\u51fd\u6570\u8c03\u7528\u3002\u8fd9\u6837\uff0c\u7f16\u8bd1\u5668\u53ef\u80fd\u4f1a\u5c06<code>add<\/code>\u51fd\u6570\u7684\u4ee3\u7801\u76f4\u63a5\u5d4c\u5165\u5230\u8c03\u7528\u5b83\u7684\u5730\u65b9\uff0c\u4ece\u800c\u6d88\u9664\u4e86\u51fd\u6570\u8c03\u7528\u7684\u5f00\u9500\u3002<\/p>\n<p><strong>\u4f18\u52bf<\/strong>\uff1a<\/p>\n<ul>\n<li>\u7531\u4e8e\u51cf\u5c11\u4e86\u51fd\u6570\u8c03\u7528\u7684\u5f00\u9500\uff0c<code>add<\/code>\u51fd\u6570\u7684\u6267\u884c\u53ef\u80fd\u4f1a\u66f4\u5feb\uff0c\u5c24\u5176\u662f\u5728\u8be5\u51fd\u6570\u88ab\u9891\u7e41\u8c03\u7528\u7684\u60c5\u51b5\u4e0b\u3002<\/li>\n<li>inline\u51fd\u6570\u901a\u5e38\u6bd4\u5b8f\u66f4\u5b89\u5168\uff0c\u56e0\u4e3a\u5b83\u4eec\u4f1a\u8fdb\u884c\u7c7b\u578b\u68c0\u67e5\uff0c\u5e76\u4e14\u9075\u5faa\u4f5c\u7528\u57df\u89c4\u5219\u3002<\/li>\n<\/ul>\n<p><strong>\u52a3\u52bf<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5982\u679cinline\u51fd\u6570\u7684\u5b9e\u73b0\u975e\u5e38\u590d\u6742\u6216\u8005\u51fd\u6570\u4f53\u5f88\u5927\uff0c\u90a3\u4e48\u5c06\u5176\u4ee3\u7801\u76f4\u63a5\u63d2\u5165\u5230\u6bcf\u4e2a\u8c03\u7528\u70b9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u751f\u6210\u7684\u4ee3\u7801\u4f53\u79ef\u663e\u8457\u589e\u52a0\uff0c\u5373\u4ee3\u7801\u81a8\u80c0\u3002<\/li>\n<li>inline\u51fd\u6570\u53ef\u80fd\u4f1a\u589e\u52a0\u7f16\u8bd1\u5668\u7684\u590d\u6742\u6027\uff0c\u56e0\u4e3a\u7f16\u8bd1\u5668\u9700\u8981\u51b3\u5b9a\u54ea\u4e9b\u51fd\u6570\u5e94\u8be5\u5185\u8054\uff0c\u54ea\u4e9b\u4e0d\u5e94\u8be5\u3002\u8fd9\u53ef\u80fd\u4f1a\u589e\u52a0\u7f16\u8bd1\u65f6\u95f4\u3002<\/li>\n<\/ul>\n<p>\u8bf7\u6ce8\u610f\uff0c\u867d\u7136\u6211\u4eec\u5728\u51fd\u6570\u58f0\u660e\u4e2d\u4f7f\u7528\u4e86<code>inline<\/code>\u5173\u952e\u5b57\uff0c\u4f46\u6700\u7ec8\u662f\u5426\u5185\u8054\u4ee5\u53ca\u5185\u8054\u7684\u7a0b\u5ea6\u4ecd\u7136\u53d6\u51b3\u4e8e\u7f16\u8bd1\u5668\u7684\u4f18\u5316\u7b56\u7565\u3002\u7f16\u8bd1\u5668\u53ef\u80fd\u4f1a\u5ffd\u7565\u6211\u4eec\u7684\u8bf7\u6c42\uff0c\u7279\u522b\u662f\u5f53\u51fd\u6570\u4f53\u5f88\u5927\u6216\u8005\u5185\u8054\u4e0d\u4f1a\u5e26\u6765\u6027\u80fd\u63d0\u5347\u65f6\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0cinline\u51fd\u6570\u5e76\u4e0d\u662f\u603b\u662f\u80fd\u591f\u63d0\u9ad8\u6027\u80fd\u3002\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u7531\u4e8e\u4ee3\u7801\u81a8\u80c0\u6216\u6307\u4ee4\u7f13\u5b58\u672a\u547d\u4e2d\u7b49\u539f\u56e0\uff0c\u5185\u8054\u51fd\u6570\u751a\u81f3\u53ef\u80fd\u5bfc\u81f4\u6027\u80fd\u4e0b\u964d\u3002\u56e0\u6b64\uff0c\u5728\u51b3\u5b9a\u662f\u5426\u4f7f\u7528inline\u51fd\u6570\u65f6\uff0c\u5e94\u8be5\u6839\u636e\u5177\u4f53\u60c5\u51b5\u8fdb\u884c\u6743\u8861\u548c\u6d4b\u8bd5\u3002<\/p>\n<h2 id=\"final\u548coverride\">final\u548coverride<\/h2>\n<p><strong>\u95ee:final\u548coverride\u7684\u4f5c\u7528\uff0c\u4ee5\u53ca\u4f7f\u7528\u573a\u5408<\/strong><\/p>\n<p><code>final<\/code>\u548c<code>override<\/code>\u662f\u4e24\u79cd\u5e38\u7528\u4e8eJava\u548cC++\u7b49\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u8bed\u8a00\u7684\u5173\u952e\u5b57\uff0c\u5b83\u4eec\u5404\u81ea\u5177\u6709\u7279\u5b9a\u7684\u4f5c\u7528\u548c\u4f7f\u7528\u573a\u5408\u3002<\/p>\n<p><strong>final\u7684\u4f5c\u7528<\/strong>\uff1a<\/p>\n<p><code>final<\/code>\u5173\u952e\u5b57\u4e3b\u8981\u7528\u6765\u4fee\u9970\u7c7b\u3001\u65b9\u6cd5\u548c\u53d8\u91cf\u3002<\/p>\n<ol>\n<li><strong>\u4fee\u9970\u7c7b<\/strong>\uff1a\u5f53\u4e00\u4e2a\u7c7b\u88ab\u58f0\u660e\u4e3a<code>final<\/code>\u65f6\uff0c\u8868\u793a\u8fd9\u4e2a\u7c7b\u4e0d\u80fd\u88ab\u7ee7\u627f\u3002\u8fd9\u6709\u52a9\u4e8e\u4fdd\u62a4\u7c7b\u7684\u5b8c\u6574\u6027\u548c\u5b89\u5168\u6027\uff0c\u9632\u6b62\u5176\u4ed6\u7c7b\u6269\u5c55\u6216\u4fee\u6539\u8fd9\u4e2a\u7c7b\u7684\u884c\u4e3a\u3002\u4f8b\u5982\uff0cJava\u4e2d\u7684<code>String<\/code>\u7c7b\u5c31\u662f\u4e00\u4e2a<code>final<\/code>\u7c7b\u3002<\/li>\n<li><strong>\u4fee\u9970\u65b9\u6cd5<\/strong>\uff1a<code>final<\/code>\u65b9\u6cd5\u4e0d\u80fd\u88ab\u5b50\u7c7b\u91cd\u5199\u3002\u8fd9\u786e\u4fdd\u4e86\u65b9\u6cd5\u7684\u5b9e\u73b0\u4e0d\u4f1a\u88ab\u4fee\u6539\uff0c\u4ece\u800c\u4fdd\u6301\u65b9\u6cd5\u7684\u7a33\u5b9a\u6027\u548c\u4e00\u81f4\u6027\u3002\u5728Java\u4e2d\uff0c\u8bb8\u591a\u6838\u5fc3\u7c7b\u7684\u65b9\u6cd5\u90fd\u88ab\u58f0\u660e\u4e3a<code>final<\/code>\uff0c\u4ee5\u9632\u6b62\u5b83\u4eec\u88ab\u5b50\u7c7b\u610f\u5916\u4fee\u6539\u3002<\/li>\n<li><strong>\u4fee\u9970\u53d8\u91cf<\/strong>\uff1a<code>final<\/code>\u53d8\u91cf\u662f\u4e00\u4e2a\u5e38\u91cf\uff0c\u4e00\u65e6\u8d4b\u503c\u540e\u5c31\u4e0d\u80fd\u518d\u4fee\u6539\u3002\u8fd9\u6709\u52a9\u4e8e\u786e\u4fdd\u53d8\u91cf\u7684\u503c\u5728\u7a0b\u5e8f\u7684\u6574\u4e2a\u751f\u547d\u5468\u671f\u4e2d\u4fdd\u6301\u4e0d\u53d8\u3002<\/li>\n<\/ol>\n<p><strong>override\u7684\u4f5c\u7528<\/strong>\uff1a<\/p>\n<p><code>override<\/code>\u5173\u952e\u5b57\u7528\u4e8e\u6807\u793a\u4e00\u4e2a\u65b9\u6cd5\u91cd\u5199\u4e86\u7236\u7c7b\u4e2d\u7684\u540c\u540d\u65b9\u6cd5\u3002\u8fd9\u4e3b\u8981\u51fa\u73b0\u5728\u5b50\u7c7b\u4e2d\uff0c\u5f53\u5b50\u7c7b\u9700\u8981\u6539\u53d8\u6216\u6269\u5c55\u7236\u7c7b\u7684\u67d0\u4e2a\u65b9\u6cd5\u7684\u884c\u4e3a\u65f6\u3002<\/p>\n<ol>\n<li><strong>\u660e\u786e\u91cd\u5199\u5173\u7cfb<\/strong>\uff1a<code>override<\/code>\u6807\u8bb0\u4f7f\u5f97\u4ee3\u7801\u66f4\u52a0\u6e05\u6670\u548c\u6613\u4e8e\u7406\u89e3\uff0c\u5b83\u660e\u786e\u544a\u8bc9\u9605\u8bfb\u4ee3\u7801\u7684\u4eba\u8fd9\u4e2a\u65b9\u6cd5\u662f\u4e00\u4e2a\u91cd\u5199\u7684\u65b9\u6cd5\uff0c\u800c\u4e0d\u662f\u4e00\u4e2a\u65b0\u7684\u65b9\u6cd5\u6216\u91cd\u8f7d\u7684\u65b9\u6cd5\u3002<\/li>\n<li><strong>\u63d0\u9ad8\u4ee3\u7801\u53ef\u8bfb\u6027<\/strong>\uff1a\u4f7f\u7528<code>override<\/code>\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\uff0c\u4f7f\u5f97\u4ee3\u7801\u66f4\u5bb9\u6613\u88ab\u4ed6\u4eba\u7406\u89e3\u548c\u7ef4\u62a4\u3002<\/li>\n<li><strong>\u9632\u6b62\u9519\u8bef<\/strong>\uff1a\u901a\u8fc7\u663e\u5f0f\u5730\u4f7f\u7528<code>override<\/code>\u6807\u8bb0\uff0c\u7f16\u8bd1\u5668\u53ef\u4ee5\u5728\u7f16\u8bd1\u65f6\u68c0\u67e5\u662f\u5426\u786e\u5b9e\u91cd\u5199\u4e86\u7236\u7c7b\u7684\u65b9\u6cd5\uff0c\u4ece\u800c\u907f\u514d\u56e0\u4e3a\u65b9\u6cd5\u7b7e\u540d\u4e0d\u5339\u914d\u6216\u65b9\u6cd5\u4e0d\u5b58\u5728\u800c\u5bfc\u81f4\u7684\u9519\u8bef\u3002<\/li>\n<\/ol>\n<p><strong>\u4f7f\u7528\u573a\u5408<\/strong>\uff1a<\/p>\n<ol>\n<li>final\u7684\u4f7f\u7528\u573a\u5408\n<p>\uff1a<\/p>\n<ul>\n<li>\u5f53\u4f60\u4e0d\u5e0c\u671b\u4e00\u4e2a\u7c7b\u88ab\u5176\u4ed6\u7c7b\u7ee7\u627f\u65f6\uff0c\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u7c7b\u58f0\u660e\u4e3a<code>final<\/code>\u3002<\/li>\n<li>\u5f53\u4e00\u4e2a\u65b9\u6cd5\u662f\u6838\u5fc3\u903b\u8f91\u7684\u4e00\u90e8\u5206\uff0c\u5e76\u4e14\u4f60\u4e0d\u5e0c\u671b\u5b50\u7c7b\u6539\u53d8\u5176\u884c\u4e3a\u65f6\uff0c\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u65b9\u6cd5\u58f0\u660e\u4e3a<code>final<\/code>\u3002<\/li>\n<li>\u5f53\u4f60\u9700\u8981\u4e00\u4e2a\u53d8\u91cf\u5728\u6574\u4e2a\u7a0b\u5e8f\u4e2d\u4fdd\u6301\u4e0d\u53d8\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>final<\/code>\u6765\u4fee\u9970\u8fd9\u4e2a\u53d8\u91cf\u3002<\/li>\n<\/ul>\n<\/li>\n<li>override\u7684\u4f7f\u7528\u573a\u5408\n<p>\uff1a<\/p>\n<ul>\n<li>\u5f53\u5b50\u7c7b\u9700\u8981\u6539\u53d8\u6216\u6269\u5c55\u7236\u7c7b\u7684\u67d0\u4e2a\u65b9\u6cd5\u7684\u884c\u4e3a\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>override<\/code>\u6765\u91cd\u5199\u8fd9\u4e2a\u65b9\u6cd5\u3002<\/li>\n<li>\u5728\u5b9e\u73b0\u63a5\u53e3\u6216\u7ee7\u627f\u62bd\u8c61\u7c7b\u65f6\uff0c\u5fc5\u987b\u5b9e\u73b0\u6216\u91cd\u5199\u5176\u4e2d\u7684\u62bd\u8c61\u65b9\u6cd5\uff0c\u6b64\u65f6\u53ef\u4ee5\u4f7f\u7528<code>override<\/code>\u6765\u660e\u786e\u6807\u8bc6\u8fd9\u4e9b\u65b9\u6cd5\u7684\u91cd\u5199\u5173\u7cfb\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u603b\u7684\u6765\u8bf4\uff0c<code>final<\/code>\u548c<code>override<\/code>\u662f\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u4e24\u4e2a\u5173\u952e\u5b57\uff0c\u5b83\u4eec\u5404\u81ea\u5728\u4fdd\u62a4\u7c7b\u7684\u5b8c\u6574\u6027\u3001\u786e\u4fdd\u65b9\u6cd5\u7684\u7a33\u5b9a\u6027\u548c\u4e00\u81f4\u6027\u3001\u4ee5\u53ca\u5b9e\u73b0\u591a\u6001\u884c\u4e3a\u7b49\u65b9\u9762\u53d1\u6325\u7740\u91cd\u8981\u4f5c\u7528\u3002\u5728\u9002\u5f53\u7684\u4f7f\u7528\u573a\u5408\u4e0b\uff0c\u5b83\u4eec\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u7f16\u5199\u66f4\u52a0\u5065\u58ee\u3001\u6e05\u6670\u548c\u6613\u4e8e\u7ef4\u62a4\u7684\u4ee3\u7801\u3002<\/p>\n<h2 id=\"delete\u6570\u7ec4\">Delete\u6570\u7ec4<\/h2>\n<p><strong>\u95ee:Delete\u6570\u7ec4\u7684\u4e00\u90e8\u5206\u4f1a\u53d1\u751f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u51fa\u73b0\u5f02\u5e38\uff1f<\/strong><\/p>\n<p>\u5220\u9664\u6570\u7ec4\u7684\u4e00\u90e8\u5206\u53ef\u80fd\u4f1a\u5bfc\u81f4\u591a\u79cd\u7ed3\u679c\u548c\u5f02\u5e38\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u6240\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\u3001\u4e0a\u4e0b\u6587\u73af\u5883\u4ee5\u53ca\u5220\u9664\u64cd\u4f5c\u7684\u65b9\u5f0f\u3002\u4ee5\u4e0b\u662f\u53ef\u80fd\u53d1\u751f\u7684\u60c5\u51b5\u53ca\u5f02\u5e38\u539f\u56e0\uff1a<\/p>\n<ol>\n<li><strong>\u6570\u7ec4\u9996\u5730\u5740\u53d8\u66f4<\/strong>\uff1a\u5982\u679c\u65e0\u610f\u4e2d\u66f4\u6539\u4e86\u6570\u7ec4\u7684\u9996\u5730\u5740\uff0c\u5982\u901a\u8fc7\u9012\u589e\u64cd\u4f5c\uff08<code>a++<\/code>\uff09\uff0c\u90a3\u4e48\u5c1d\u8bd5\u8bbf\u95ee\u6216\u5220\u9664\u8be5\u6570\u7ec4\u7684\u90e8\u5206\u5143\u7d20\u53ef\u80fd\u4f1a\u5bfc\u81f4\u95ee\u9898\uff0c\u56e0\u4e3a\u4f60\u73b0\u5728\u53ef\u80fd\u6307\u5411\u4e86\u4e00\u4e2a\u9519\u8bef\u7684\u5185\u5b58\u4f4d\u7f6e\u3002<\/li>\n<li><strong>\u4f5c\u7528\u57df\u95ee\u9898<\/strong>\uff1a\u5982\u679c\u5728\u4e00\u4e2a\u51fd\u6570\u4f53\u5185\u5206\u914d\u4e86\u6570\u7ec4\uff0c\u5374\u5728\u53e6\u4e00\u4e2a\u51fd\u6570\u4f53\u5185\u5c1d\u8bd5\u5220\u9664\u5b83\uff0c\u53ef\u80fd\u4f1a\u56e0\u4e3a\u4f5c\u7528\u57df\u7684\u95ee\u9898\u800c\u5bfc\u81f4\u9519\u8bef\u3002\u5f53\u6570\u7ec4\u7684\u4f5c\u7528\u57df\u7ed3\u675f\u65f6\uff0c\u5b83\u4f1a\u88ab\u81ea\u52a8\u91ca\u653e\uff0c\u6b64\u65f6\u5c1d\u8bd5\u5220\u9664\u5b83\u53ef\u80fd\u4f1a\u5f15\u53d1\u5f02\u5e38\u3002<\/li>\n<li><strong>\u91cd\u590d\u5220\u9664<\/strong>\uff1a\u5982\u679c\u5df2\u7ecf\u5220\u9664\u8fc7\u6570\u7ec4\u7684\u4e00\u90e8\u5206\uff0c\u518d\u6b21\u5c1d\u8bd5\u5220\u9664\u76f8\u540c\u7684\u90e8\u5206\u4f1a\u5bfc\u81f4\u95ee\u9898\uff0c\u56e0\u4e3a\u8fd9\u90e8\u5206\u5185\u5b58\u53ef\u80fd\u5df2\u7ecf\u88ab\u91ca\u653e\u6216\u6807\u8bb0\u4e3a\u4e0d\u53ef\u7528\u3002<\/li>\n<li><strong>\u5185\u5b58\u8bbf\u95ee\u8d8a\u754c<\/strong>\uff1a\u5f53\u5220\u9664\u6570\u7ec4\u7684\u4e00\u90e8\u5206\u65f6\uff0c\u5982\u679c\u4e0d\u5c0f\u5fc3\u4fee\u6539\u4e86\u6570\u7ec4\u8fb9\u754c\u5916\u7684\u5185\u5b58\uff08\u5982\u7ba1\u7406\u5355\u5143\u6216\u5185\u5b58\u8fb9\u754c\u6807\u5fd7\uff09\uff0c\u90a3\u4e48\u5728\u4e0b\u6b21\u8bbf\u95ee\u6216\u91ca\u653e\u6570\u7ec4\u65f6\u53ef\u80fd\u4f1a\u51fa\u9519\u3002\u4f8b\u5982\uff0c\u5728VC\u5206\u914d\u7684\u5185\u5b58\u4e2d\uff0c\u9664\u4e86\u7528\u6237\u8bf7\u6c42\u7684\u6570\u636e\u7a7a\u95f4\u5916\uff0c\u8fd8\u4f1a\u5206\u914d\u4e00\u4e9b\u989d\u5916\u7684\u7ba1\u7406\u5185\u5b58\u3002\u5982\u679c\u4fee\u6539\u4e86\u8fd9\u4e9b\u7ba1\u7406\u4fe1\u606f\uff0c\u90a3\u4e48\u5728\u91ca\u653e\u6570\u7ec4\u65f6\u5c31\u4f1a\u51fa\u9519\u3002<\/li>\n<li><strong>\u539f\u751f\u64cd\u4f5c\u7b26\u4e0e\u7279\u5b9a\u6846\u67b6\/\u5e93\u7684\u884c\u4e3a\u5dee\u5f02<\/strong>\uff1a\u5728\u67d0\u4e9b\u7f16\u7a0b\u8bed\u8a00\u6216\u6846\u67b6\u4e2d\uff0c\u4f7f\u7528\u539f\u751f\u64cd\u4f5c\u7b26\uff08\u5982JavaScript\u4e2d\u7684<code>delete<\/code>\uff09\u5220\u9664\u6570\u7ec4\u5143\u7d20\u65f6\uff0c\u53ef\u80fd\u4e0d\u4f1a\u6539\u53d8\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u800c\u662f\u5c06\u5143\u7d20\u6807\u8bb0\u4e3a<code>undefined<\/code>\u3002\u7136\u800c\uff0c\u67d0\u4e9b\u6846\u67b6\u6216\u5e93\uff08\u5982Vue.js\u4e2d\u7684<code>Vue.delete<\/code>\uff09\u53ef\u80fd\u4f1a\u66f4\u65b0\u6570\u7ec4\u957f\u5ea6\u5e76\u5b8c\u5168\u79fb\u9664\u5143\u7d20\u3002\u8fd9\u79cd\u5dee\u5f02\u53ef\u80fd\u5bfc\u81f4\u5728\u4f7f\u7528\u7279\u5b9a\u6846\u67b6\u6216\u5e93\u65f6\u51fa\u73b0\u95ee\u9898\u3002<\/li>\n<li><strong>\u5e95\u5c42\u5185\u5b58\u7ba1\u7406\u95ee\u9898<\/strong>\uff1a\u76f4\u63a5\u64cd\u4f5c\u5185\u5b58\uff08\u5982\u4f7f\u7528C\u6216C++\u7684\u6307\u9488\uff09\u65f6\uff0c\u5982\u679c\u4e0d\u6b63\u786e\u5730\u7ba1\u7406\u5185\u5b58\uff08\u5982\u672a\u521d\u59cb\u5316\u6307\u9488\u3001\u91ca\u653e\u540e\u7ee7\u7eed\u4f7f\u7528\u7b49\uff09\uff0c\u53ef\u80fd\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u6216\u5f02\u5e38\u3002<\/li>\n<\/ol>\n<p>\u4e3a\u4e86\u907f\u514d\u8fd9\u4e9b\u95ee\u9898\uff0c\u5efa\u8bae\u5728\u5220\u9664\u6570\u7ec4\u90e8\u5206\u4e4b\u524d\u786e\u4fdd\uff1a<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>\u6570\u7ec4\u7684\u9996\u5730\u5740\u672a\u88ab\u66f4\u6539\u3002<\/li>\n<li>\u5728\u6b63\u786e\u7684\u4f5c\u7528\u57df\u5185\u64cd\u4f5c\u6570\u7ec4\u3002<\/li>\n<li>\u907f\u514d\u91cd\u590d\u5220\u9664\u540c\u4e00\u90e8\u5206\u3002<\/li>\n<li>\u786e\u4fdd\u4e0d\u8d8a\u754c\u8bbf\u95ee\u6216\u4fee\u6539\u6570\u7ec4\u53ca\u5176\u5468\u56f4\u7684\u5185\u5b58\u3002<\/li>\n<li>\u7406\u89e3\u5e76\u9075\u5faa\u6240\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\u3001\u6846\u67b6\u6216\u5e93\u7684\u6700\u4f73\u5b9e\u8df5\u548c\u89c4\u5219\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2 id=\"\u6307\u9488\u8d8a\u754c\">\u6307\u9488\u8d8a\u754c<\/h2>\n<p><strong>\u95ee\uff1a\u7cfb\u7edf\u662f\u5982\u4f55\u77e5\u9053\u6307\u9488\u8d8a\u754c\u7684\uff1f<\/strong><\/p>\n<p><strong>_CrtMemBlockHeader<\/strong> \uff1a\u8fd9\u4e2a\u7ed3\u6784\u4f53\uff0c\u5b58\u653e\u4e86\u52a8\u6001\u7533\u8bf7\u5f97\u5230\u7684\u5185\u5b58\u5757\u7684\u5404\u79cd\u4fe1\u606f\uff0c\u5e76\u4e14\u8fd4\u56de\u5230\u4f60\u7684\u6307\u9488\u4e0a\u9762\u3002\u5177\u4f53\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-c++\" lang=\"c++\">typedef struct _CrtMemBlockHeader \n{      \n\u3000\u3000\/\/ \u6307\u5411\u4e0b\u4e00\u5757\u6570\u636e\u5757\u7684\u6307\u9488       \n\u3000\u3000struct _CrtMemBlockHeader *pBlockHeaderNext;        \n    \/\/ \u6307\u5411\u524d\u4e00\u5757\u6570\u636e\u5757\u7684\u6307\u9488   \n    struct _CrtMemBlockHeader *pBlockHeaderPrev;    \n\n    \/\/ File name\uff1a\u8bf7\u6c42\u5185\u5b58\u5206\u914d\u64cd\u4f5c\u7684\u90a3\u884c\u4ee3\u7801\u6240\u5728\u7684\u6587\u4ef6\u7684\u8def\u5f84\u548c\u540d\u79f0\uff0c\u4f46\u5b9e\u9645\u4e0a\u662f\u7a7a\u6307\u9488  \n    char *szFileName;  \n    \/\/ Line number\uff1a\u884c\u53f7\uff0c\u8bf7\u6c42\u5185\u5b58\u5206\u914d\u64cd\u4f5c\u7684\u90a3\u884c\u4ee3\u7801\u7684\u884c\u53f7   \n    int nLine;            \n\n    \/\/ \u8bf7\u6c42\u5206\u914d\u7684\u5927\u5c0f    size_t nDataSize;     \n\n    \/\/ Type of block \u7c7b\u578b  \n    int nBlockUse;      \n    \/\/ \u8bf7\u6c42\u53f7 \n    long lRequest;        \n    \/\/ \u8fd9\u4e2agap\uff0c\u6b63\u662fcpp\u4e2d\u5bf9\u4e8e\u6307\u9488\u7684\u754c\u9650 \n    unsigned char gap[nNoMansLandSize];\n} _CrtMemBlockHeader;\n\n\n<\/code><\/pre>\n<p>VC\u4e0b\u6709\u4e00\u4e2a\u7ed3\u6784\u4f53_CrtMemBlockHeader\uff0c\u91cc\u9762\u6709\u4e00\u4e2aGap\u5c5e\u6027\uff0c\u8fd9\u4e2aGap\u6570\u7ec4\u653e\u5728\u4f60\u7684\u6307\u9488\u6570\u636e\u7684\u540e\u9762\uff0c\u9ed8\u8ba4\u4e3a0xFD\uff0c\u5f53\u68c0\u6d4b\u5230\u4f60\u7684\u6570\u636e\u540e\u4e0d\u662f0xFD\u7684\u65f6\u5019\u5c31\u8bf4\u660e\u7684\u4f60\u7684\u6570\u636e\u8d8a\u754c\u4e86\u3002<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240329\/2024032901.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240329\/2024032901.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" \/><\/div><\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\u6709\u51e0\u4e2a\u95ee\u9898\uff0c\u9996\u5148\uff0c\u6211\u4eec\u6765\u9010\u4e00\u89e3\u91ca\u8fd9\u4e9b\u95ee\u9898\uff0c\u7136\u540e\u518d\u603b\u7ed3\u3002<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>\u5206\u914d\u5185\u5b58\u548c\u8d8a\u754c\u8bbf\u95ee:<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code class=\"language-c\" lang=\"c\">int* p = (int*)malloc(sizeof(int));\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u4f60\u5206\u914d\u4e86\u8db3\u591f\u7684\u5185\u5b58\u6765\u5b58\u50a8\u4e00\u4e2a<code>int<\/code>\u7c7b\u578b\u7684\u53d8\u91cf\u3002<code>p<\/code>\u73b0\u5728\u6307\u5411\u8fd9\u5757\u5185\u5b58\u7684\u8d77\u59cb\u5730\u5740\u3002<\/p>\n<pre><code class=\"language-c\" lang=\"c\">*(p+1) = 1;\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u4f60\u8bd5\u56fe\u8bbf\u95ee<code>p<\/code>\u6307\u5411\u7684\u5185\u5b58\u5757\u540e\u9762\u7684\u5185\u5b58\uff0c\u5e76\u5c06\u503c<code>1<\/code>\u5b58\u50a8\u5728\u90a3\u91cc\u3002\u8fd9\u662f\u8d8a\u754c\u8bbf\u95ee\uff0c\u56e0\u4e3a\u5b83\u8d85\u51fa\u4e86\u4f60\u5206\u914d\u7684\u5185\u5b58\u8303\u56f4\u3002\u8fd9\u6837\u7684\u64cd\u4f5c\u53ef\u80fd\u5bfc\u81f4\u672a\u5b9a\u4e49\u884c\u4e3a\uff0c\u5305\u62ec\u7a0b\u5e8f\u5d29\u6e83\u6216\u6570\u636e\u635f\u574f\u3002<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>\u9519\u8bef\u7684<code>free<\/code>\u8c03\u7528:<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code class=\"language-c\" lang=\"c\">free(p);\n<\/code><\/pre>\n<p>\u5f53\u4f60\u8c03\u7528<code>free(p)<\/code>\u65f6\uff0c\u4f60\u544a\u8bc9\u7cfb\u7edf\u4f60\u5df2\u7ecf\u5b8c\u6210\u4e86\u5bf9<code>p<\/code>\u6307\u5411\u7684\u5185\u5b58\u5757\u7684\u4f7f\u7528\uff0c\u5e76\u53ef\u4ee5\u5c06\u5176\u91ca\u653e\u56de\u7cfb\u7edf\u3002\u7136\u800c\uff0c\u7531\u4e8e\u4e4b\u524d\u7684\u8d8a\u754c\u8bbf\u95ee\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u53ef\u80fd\u65e0\u6cd5\u6b63\u5e38\u5de5\u4f5c\uff0c\u6216\u8005\u5373\u4f7f\u53ef\u4ee5\uff0c\u540e\u7eed\u5bf9<code>p<\/code>\u7684\u89e3\u5f15\u7528\u4e5f\u662f\u975e\u6cd5\u7684\u3002<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>\u89e3\u5f15\u7528\u5df2\u91ca\u653e\u7684\u5185\u5b58:<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code class=\"language-c\" lang=\"c\">*(p-1) = 1;\n<\/code><\/pre>\n<p>\u5728\u8c03\u7528<code>free(p)<\/code>\u4e4b\u540e\uff0c\u4f60\u8bd5\u56fe\u8bbf\u95ee<code>p<\/code>\u6307\u5411\u7684\u5185\u5b58\uff08\u6216\u5b83\u4e4b\u524d\u7684\u5185\u5b58\uff09\uff0c\u8fd9\u662f\u975e\u6cd5\u7684\u3002<code>p<\/code>\u6307\u5411\u7684\u5185\u5b58\u5df2\u7ecf\u88ab\u91ca\u653e\uff0c\u4f60\u4e0d\u80fd\u518d\u8bbf\u95ee\u6216\u4fee\u6539\u5b83\u3002\u8fd9\u6837\u7684\u64cd\u4f5c\u53ef\u80fd\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u6216\u5176\u4ed6\u672a\u5b9a\u4e49\u884c\u4e3a\u3002<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>\u91cd\u590d\u91ca\u653e\u540c\u4e00\u5757\u5185\u5b58:<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code class=\"language-c\" lang=\"c\">free(p); \/\/ \u4f9d\u65e7\u5d29\u6e83\n<\/code><\/pre>\n<p>\u5c1d\u8bd5\u518d\u6b21\u91ca\u653e\u540c\u4e00\u5757\u5185\u5b58\u662f\u53e6\u4e00\u4e2a\u9519\u8bef\u3002<code>free<\/code>\u5e94\u8be5\u53ea\u88ab\u8c03\u7528\u4e00\u6b21\u9488\u5bf9\u540c\u4e00\u5757\u5185\u5b58\u3002\u91cd\u590d\u8c03\u7528<code>free<\/code>\u53ef\u80fd\u5bfc\u81f4\u672a\u5b9a\u4e49\u884c\u4e3a\uff0c\u901a\u5e38\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u3002<\/p>\n<h2 id=\"\u4f18\u5316\">\u4f18\u5316<\/h2>\n<p><strong>C++\u7f16\u8bd1\u5668\u6709\u54ea\u4e9b\u5e38\u89c1\u7684\u4f18\u5316\uff1f\u542c\u8bf4\u8fc7RVO\uff08NRVO\uff09\u4e48\uff1f<\/strong><\/p>\n<p>C++\u7f16\u8bd1\u5668\u4e3a\u4e86\u751f\u6210\u66f4\u9ad8\u6548\u7684\u4ee3\u7801\uff0c\u901a\u5e38\u4f1a\u8fdb\u884c\u4e00\u7cfb\u5217\u7684\u4f18\u5316\u3002\u8fd9\u4e9b\u4f18\u5316\u6d89\u53ca\u4ee3\u7801\u7684\u591a\u4e2a\u65b9\u9762\uff0c\u5305\u62ec\u5faa\u73af\u3001\u51fd\u6570\u8c03\u7528\u3001\u5185\u5b58\u7ba1\u7406\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9bC++\u7f16\u8bd1\u5668\u5e38\u89c1\u7684\u4f18\u5316\u6280\u672f\uff1a<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li><strong>\u5185\u8054\u51fd\u6570\uff08Inline Functions\uff09<\/strong>\uff1a\u5bf9\u4e8e\u51fd\u6570\u4f53\u8f83\u5c0f\u4e14\u9891\u7e41\u8c03\u7528\u7684\u51fd\u6570\uff0c\u7f16\u8bd1\u5668\u53ef\u80fd\u4f1a\u5c06\u5176\u5185\u8054\u5c55\u5f00\uff0c\u5373\u5c06\u51fd\u6570\u8c03\u7528\u66ff\u6362\u4e3a\u51fd\u6570\u4f53\u672c\u8eab\uff0c\u4ee5\u51cf\u5c11\u51fd\u6570\u8c03\u7528\u7684\u5f00\u9500\u3002<\/li>\n<li><strong>\u5faa\u73af\u5c55\u5f00\uff08Loop Unrolling\uff09<\/strong>\uff1a\u7f16\u8bd1\u5668\u53ef\u80fd\u4f1a\u5c06\u5faa\u73af\u4e2d\u7684\u591a\u6b21\u8fed\u4ee3\u5c55\u5f00\u6210\u591a\u4e2a\u91cd\u590d\u7684\u4ee3\u7801\u5757\uff0c\u51cf\u5c11\u5faa\u73af\u63a7\u5236\u7684\u5f00\u9500\uff0c\u4ece\u800c\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6267\u884c\u901f\u5ea6\u3002<\/li>\n<li><strong>\u4ee3\u7801\u590d\u5236\uff08Code Duplication\uff09<\/strong>\uff1a\u4e3a\u4e86\u907f\u514d\u51fd\u6570\u8c03\u7528\u7684\u5f00\u9500\uff0c\u7f16\u8bd1\u5668\u53ef\u80fd\u4f1a\u5c06\u91cd\u590d\u51fa\u73b0\u7684\u4ee3\u7801\u5757\u590d\u5236\u5230\u591a\u4e2a\u4f4d\u7f6e\u3002<\/li>\n<li><strong>\u9012\u5f52\u4f18\u5316\uff08Recursive Optimization\uff09<\/strong>\uff1a\u5bf9\u4e8e\u9012\u5f52\u51fd\u6570\uff0c\u7f16\u8bd1\u5668\u53ef\u80fd\u4f1a\u8fdb\u884c\u4f18\u5316\uff0c\u5982\u5c3e\u9012\u5f52\u4f18\u5316\u6216\u9012\u5f52\u5c55\u5f00\uff0c\u4ee5\u51cf\u5c11\u9012\u5f52\u8c03\u7528\u7684\u5f00\u9500\u3002<\/li>\n<li><strong>\u5e38\u91cf\u4f20\u64ad\uff08Constant Propagation\uff09<\/strong>\uff1a\u7f16\u8bd1\u5668\u4f1a\u5c06\u5e38\u91cf\u503c\u76f4\u63a5\u4f20\u64ad\u5230\u4f7f\u7528\u8be5\u5e38\u91cf\u7684\u5730\u65b9\uff0c\u51cf\u5c11\u53d8\u91cf\u7684\u8bfb\u53d6\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u6570\u636e\u6d41\u5206\u6790\uff08Data Flow Analysis\uff09<\/strong>\uff1a\u901a\u8fc7\u5bf9\u7a0b\u5e8f\u7684\u6570\u636e\u6d41\u8fdb\u884c\u5206\u6790\uff0c\u7f16\u8bd1\u5668\u53ef\u4ee5\u4f18\u5316\u53d8\u91cf\u7684\u4f7f\u7528\u65b9\u5f0f\uff0c\u5982\u5bc4\u5b58\u5668\u5206\u914d\u3001\u5faa\u73af\u4e0d\u53d8\u91cf\u5916\u63d0\u7b49\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u81f3\u4e8e\u4f60\u63d0\u5230\u7684RVO\uff08\u8fd4\u56de\u503c\u4f18\u5316\uff09\u548cNRVO\uff08\u547d\u540d\u8fd4\u56de\u503c\u4f18\u5316\uff09\uff0c\u5b83\u4eec\u786e\u5b9e\u662fC++\u7f16\u8bd1\u5668\u7528\u4e8e\u4f18\u5316\u4ee3\u7801\u7684\u91cd\u8981\u6280\u672f\u3002<\/p>\n<p><strong>\u8fd4\u56de\u503c\u4f18\u5316\uff08RVO\uff09<\/strong>\uff1a\u5f53\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u5bf9\u8c61\u65f6\uff0c\u7f16\u8bd1\u5668\u53ef\u80fd\u4f1a\u76f4\u63a5\u5728\u8c03\u7528\u8005\u7684\u4e0a\u4e0b\u6587\u4e2d\u6784\u9020\u8be5\u5bf9\u8c61\uff0c\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u590d\u5236\u6216\u79fb\u52a8\u64cd\u4f5c\u3002\u8fd9\u5728\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u4e34\u65f6\u201ctemp\u201d\u5bf9\u8c61\u65f6\u5c24\u5176\u6709\u7528\u3002<\/p>\n<p><strong>\u547d\u540d\u8fd4\u56de\u503c\u4f18\u5316\uff08NRVO\uff09<\/strong>\uff1a\u6bd4RVO\u8fdb\u4e00\u6b65\u4f18\u5316\u3002\u5bf9\u4e8eRVO\uff0c\u5982\u679c\u51fd\u6570\u5728\u8fd4\u56de\u524d\u521b\u5efa\u4e86\u4e00\u4e2a\u4e34\u65f6\u53d8\u91cf\uff0c\u8fd9\u4e2a\u4e34\u65f6\u53d8\u91cf\u8fd8\u662f\u4f1a\u88ab\u6784\u9020\u7684\uff0c\u53c2\u8003\u4e0b\u9762\u4ee3\u7801<\/p>\n<pre><code class=\"language-c++\" lang=\"c++\">Point3d Factory()\n{\nPoint3d po(1,2, 3);\nreturn po;\n}\n\/\/RVO\u4f18\u5316\u540e\nvoid Factory(Point3d &amp;_result)\n{\nPoint3d po(1,2,3);\n_result.Point3d::Point3d(po);\nreturn;\n}\n\/\/NRVO\u4f18\u5316\u540e\nvoid Factory(Point3d &amp;_result)\n{\n_result.Point3d::Point3d(1, 2, 3);\nreturn;\n}\n<\/code><\/pre>\n<p>NRVO\u5219\u76f4\u63a5\u8df3\u8fc7\u4e34\u65f6\u5bf9\u8c61\u7684\u6784\u9020\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u4e2a\u5c0f\u7684\u6280\u5de7\uff0cstatic\u53d8\u91cf\u4e0d\u4f1a\u88ab\u4f18\u5316<\/p>\n<p>\u5173\u4e8estatic\u7684\u77e5\u8bc6<\/p>\n<p>\u5728C++\u4e2d\uff0c<code>static<\/code>\u5173\u952e\u5b57\u5177\u6709\u591a\u79cd\u7528\u9014\uff0c\u5b83\u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u4e0a\u4e0b\u6587\u4e2d\u6539\u53d8\u53d8\u91cf\u7684\u751f\u547d\u5468\u671f\u3001\u53ef\u89c1\u6027\u6216\u94fe\u63a5\u6027\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u8ba8\u8bba<code>static<\/code>\u5728C++\u4e2d\u7684\u51e0\u79cd\u4e3b\u8981\u7528\u9014\uff1a<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li><strong>\u5c40\u90e8\u9759\u6001\u53d8\u91cf<\/strong>\uff1a<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u5f53<code>static<\/code>\u7528\u4e8e\u51fd\u6570\u5185\u90e8\u58f0\u660e\u7684\u53d8\u91cf\u65f6\uff0c\u8be5\u53d8\u91cf\u5177\u6709\u9759\u6001\u5b58\u50a8\u671f\u3002\u8fd9\u610f\u5473\u7740\u8be5\u53d8\u91cf\u53ea\u4f1a\u88ab\u521d\u59cb\u5316\u4e00\u6b21\uff0c\u5e76\u4e14\u5b83\u7684\u751f\u547d\u5468\u671f\u662f\u6574\u4e2a\u7a0b\u5e8f\u7684\u6267\u884c\u671f\u95f4\uff0c\u800c\u4e0d\u662f\u4ec5\u5728\u5b9a\u4e49\u5b83\u7684\u51fd\u6570\u88ab\u8c03\u7528\u65f6\u3002<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">void foo() {  \n    static int count = 0; \/\/ \u5c40\u90e8\u9759\u6001\u53d8\u91cf  \n    count++;  \n    std::cout &lt;&lt; count &lt;&lt; std::endl;  \n}  \n  \nint main() {  \n    foo(); \/\/ \u8f93\u51fa 1  \n    foo(); \/\/ \u8f93\u51fa 2  \n    \/\/ ... \u6bcf\u6b21\u8c03\u7528foo()\uff0ccount\u90fd\u4f1a\u9012\u589e  \n}\n<\/code><\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c<code>count<\/code>\u662f\u4e00\u4e2a\u5c40\u90e8\u9759\u6001\u53d8\u91cf\uff0c\u5b83\u5728<code>foo<\/code>\u51fd\u6570\u7b2c\u4e00\u6b21\u88ab\u8c03\u7528\u65f6\u521d\u59cb\u5316\uff0c\u5e76\u5728\u540e\u7eed\u7684\u8c03\u7528\u4e2d\u4fdd\u6301\u5176\u503c\u3002<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol start=\"2\">\n<li><strong>\u7c7b\u9759\u6001\u6210\u5458<\/strong>\uff1a<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u5f53<code>static<\/code>\u7528\u4e8e\u7c7b\u7684\u6210\u5458\u53d8\u91cf\u6216\u6210\u5458\u51fd\u6570\u65f6\uff0c\u8be5\u6210\u5458\u5c5e\u4e8e\u7c7b\u672c\u8eab\uff0c\u800c\u4e0d\u662f\u7c7b\u7684\u4efb\u4f55\u7279\u5b9a\u5bf9\u8c61\u3002\u6240\u6709\u5bf9\u8c61\u5171\u4eab\u540c\u4e00\u4e2a\u9759\u6001\u6210\u5458\u3002\u9759\u6001\u6210\u5458\u53d8\u91cf\u5fc5\u987b\u5728\u7c7b\u5b9a\u4e49\u5916\u90e8\u8fdb\u884c\u5b9a\u4e49\u548c\u521d\u59cb\u5316\u3002<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">class MyClass {  \npublic:  \n    static int count; \/\/ \u9759\u6001\u6210\u5458\u53d8\u91cf\u58f0\u660e  \n    void increment() {  \n        count++; \/\/ \u8bbf\u95ee\u9759\u6001\u6210\u5458\u53d8\u91cf  \n    }  \n    static void printCount() { \/\/ \u9759\u6001\u6210\u5458\u51fd\u6570  \n        std::cout &lt;&lt; count &lt;&lt; std::endl;  \n    }  \n};  \n  \n\/\/ \u9759\u6001\u6210\u5458\u53d8\u91cf\u5b9a\u4e49\u548c\u521d\u59cb\u5316  \nint MyClass::count = 0;  \n  \nint main() {  \n    MyClass obj1, obj2;  \n    obj1.increment(); \/\/ count \u53d8\u4e3a 1  \n    obj2.printCount(); \/\/ \u8f93\u51fa 1\uff0c\u56e0\u4e3aobj1\u548cobj2\u5171\u4eab\u540c\u4e00\u4e2acount  \n}\n<\/code><\/pre>\n<p>\u9759\u6001\u6210\u5458\u51fd\u6570\u53ea\u80fd\u8bbf\u95ee\u9759\u6001\u6210\u5458\u53d8\u91cf\u6216\u5176\u4ed6\u9759\u6001\u6210\u5458\u51fd\u6570\uff0c\u56e0\u4e3a\u5b83\u4eec\u4e0d\u4f9d\u8d56\u4e8e\u7c7b\u7684\u4efb\u4f55\u7279\u5b9a\u5bf9\u8c61\u3002<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol start=\"3\">\n<li><strong>\u9759\u6001\u5168\u5c40\u53d8\u91cf\u548c\u9759\u6001\u51fd\u6570<\/strong>\uff1a<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u5728\u6587\u4ef6\u4f5c\u7528\u57df\uff08\u5373\u5168\u5c40\u4f5c\u7528\u57df\uff0c\u4f46\u4e0d\u5728\u4efb\u4f55\u51fd\u6570\u6216\u7c7b\u5185\u90e8\uff09\u4e2d\uff0c<code>static<\/code>\u7528\u4e8e\u58f0\u660e\u9759\u6001\u5168\u5c40\u53d8\u91cf\u6216\u9759\u6001\u51fd\u6570\u3002\u8fd9\u6837\u7684\u53d8\u91cf\u6216\u51fd\u6570\u53ea\u5bf9\u5176\u5b9a\u4e49\u7684\u6587\u4ef6\u53ef\u89c1\uff0c\u5bf9\u5176\u4ed6\u6587\u4ef6\u662f\u4e0d\u53ef\u89c1\u7684\uff0c\u5373\u4f7f\u5b83\u4eec\u4f7f\u7528\u4e86<code>extern<\/code>\u5173\u952e\u5b57\u6765\u58f0\u660e\u3002\u8fd9\u63d0\u4f9b\u4e86\u4e00\u79cd\u5c01\u88c5\u673a\u5236\uff0c\u7528\u4e8e\u9650\u5236\u53d8\u91cf\u6216\u51fd\u6570\u7684\u53ef\u89c1\u6027\u3002<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">\/\/ file1.cpp  \nstatic int myStaticGlobal = 42; \/\/ \u53ea\u5bf9file1.cpp\u53ef\u89c1  \n  \nstatic void myStaticFunction() {  \n    \/\/ ...  \n}  \n  \n\/\/ file2.cpp  \nextern int myStaticGlobal; \/\/ \u9519\u8bef\uff01myStaticGlobal\u5728file2.cpp\u4e2d\u4e0d\u53ef\u89c1  \nextern void myStaticFunction(); \/\/ \u9519\u8bef\uff01myStaticFunction\u5728file2.cpp\u4e2d\u4e0d\u53ef\u89c1\n<\/code><\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol start=\"4\">\n<li><strong>\u9759\u6001\u7c7b\u5185\u90e8\u53d8\u91cf<\/strong>\uff08C++11\u53ca\u4ee5\u540e\uff09\uff1a<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u5728C++11\u4e2d\uff0c\u53ef\u4ee5\u5728\u7c7b\u5185\u90e8\u5b9a\u4e49\u9759\u6001\u5e38\u91cf\u6574\u578b\u6210\u5458\uff0c\u5e76\u7ed9\u5b83\u4e00\u4e2a\u521d\u59cb\u503c\u3002\u8fd9\u6837\u7684\u6210\u5458\u5177\u6709\u5185\u90e8\u94fe\u63a5\u6027\uff0c\u5e76\u4e14\u5176\u503c\u5728\u7f16\u8bd1\u65f6\u5c31\u662f\u5df2\u77e5\u7684\u3002<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">class MyClass {  \npublic:  \n    static const int kConstant = 42; \/\/ C++11\u53ca\u4ee5\u540e\u5141\u8bb8\u7684\u9759\u6001\u5e38\u91cf\u6574\u578b\u6210\u5458  \n};  \n  \nint main() {  \n    int a = MyClass::kConstant; \/\/ \u6b63\u786e\uff0ckConstant\u7684\u503c\u662f42  \n}\n<\/code><\/pre>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u867d\u7136<code>static<\/code>\u5173\u952e\u5b57\u5728C++\u4e2d\u6709\u591a\u79cd\u7528\u9014\uff0c\u4f46\u5b83\u4e0d\u5e94\u8be5\u88ab\u968f\u610f\u4f7f\u7528\u3002\u8fc7\u5ea6\u4f7f\u7528<code>static<\/code>\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4ee3\u7801\u96be\u4ee5\u7406\u89e3\u548c\u7ef4\u62a4\uff0c\u7279\u522b\u662f\u5f53\u5b83\u5728\u4e0d\u540c\u4e0a\u4e0b\u6587\u4e2d\u6539\u53d8\u53d8\u91cf\u7684\u884c\u4e3a\u65f6\u3002\u56e0\u6b64\uff0c\u5728\u4f7f\u7528<code>static<\/code>\u65f6\u5e94\u8be5\u4ed4\u7ec6\u8003\u8651\u5176\u5f71\u54cd\uff0c\u5e76\u786e\u4fdd\u5b83\u7b26\u5408\u4ee3\u7801\u7684\u8bbe\u8ba1\u76ee\u6807\u548c\u53ef\u8bfb\u6027\u8981\u6c42\u3002<\/p>\n<h2 id=\"\u51fd\u6570\u91cd\u8f7d\">\u51fd\u6570\u91cd\u8f7d<\/h2>\n<p><strong>\u542c\u8bf4\u8fc7mangling\u4e48\uff1f<\/strong><\/p>\n<p>C++\u51fd\u6570\u91cd\u8f7d\u5e95\u5c42\u539f\u7406\u662f\u57fa\u4e8e\u7f16\u8bd1\u5668\u7684 <code>name mangling<\/code> \u673a\u5236\u3002<\/p>\n<p>\u7f16\u8bd1\u5668\u9700\u8981\u4e3aC++\u4e2d\u7684\u6240\u6709\u51fd\u6570\uff0c\u5728\u7b26\u53f7\u8868\u4e2d\u751f\u6210\u552f\u4e00\u7684\u6807\u8bc6\u7b26\uff0c\u6765\u533a\u5206\u4e0d\u540c\u7684\u51fd\u6570\u3002\u800c\u5bf9\u4e8e\u540c\u540d\u4e0d\u540c\u53c2\u7684\u51fd\u6570\uff0c\u7f16\u8bd1\u5668\u5728\u8fdb\u884c<code>name mangling<\/code>\u64cd\u4f5c\u65f6\uff0c\u4f1a\u901a\u8fc7\u51fd\u6570\u540d\u548c\u5176\u53c2\u6570\u7c7b\u578b\u751f\u6210\u552f\u4e00\u6807\u8bc6\u7b26\uff0c\u6765\u652f\u6301\u51fd\u6570\u91cd\u8f7d\u3002<\/p>\n<p>\u6ce8\u610f\uff1a<code>name mangling<\/code> \u540e\u5f97\u5230\u7684\u51fd\u6570\u6807\u8bc6\u7b26\u4e0e\u8fd4\u56de\u503c\u7c7b\u578b\u662f\u65e0\u5173\u7684\uff0c\u56e0\u6b64\u51fd\u6570\u91cd\u8f7d\u4e0e\u8fd4\u56de\u503c\u7c7b\u578b\u65e0\u5173\u3002<\/p>\n<p>\u6bd4\u5982\uff0c\u4e0b\u9762\u7684\u51e0\u4e2a\u540c\u540d\u51fd\u6570<code>func<\/code>\uff1a<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">int    func(int i)           { return 0;     }\nfloat  func(int i, float f)  { return i + f; }\ndouble func(int i, double d) { return i+d;   }\n<\/code><\/pre>\n<p>\u5728\u7ecf\u8fc7\u7f16\u8bd1\u4e2d\u7684<code>name mangling<\/code>\u64cd\u4f5c\u540e\uff0c\u5f97\u5230\u7684\u7b26\u53f7\u8868\u4e2d\u548c<code>func<\/code>\u6709\u5173\u7684\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">$ g++ main.cc -o main.o &amp;&amp; objdump -t main.o\nmain.o:     file format elf64-x86-64\n\nSYMBOL TABLE:\n0000000000001157 g     F .text  000000000000001c              _Z4funcid\n000000000000113b g     F .text  000000000000001c              _Z4funcif\n0000000000001129 g     F .text  0000000000000012              _Z4funci\n0000000000001173 g     F .text  0000000000000016              main\n...\n<\/code><\/pre>\n<p>\u5176\u4e2d\uff0c \u524d\u7f00 <code>_z<\/code> \u662fGCC\u7684\u89c4\u5b9a\uff0c<code>4<\/code> \u662f\u51fd\u6570\u540d<code>func<\/code>\u7684\u5b57\u7b26\u4e2a\u6570\uff0c<code>i<\/code>\u8868\u793a\u7b2c\u4e00\u4e2a\u51fd\u6570\u7684\u53c2\u6570\u7c7b\u578b<code>int<\/code>\uff0c<code>f<\/code>\u662f\u7b2c\u4e8c\u4e2a\u51fd\u6570\u7684\u53c2\u6570\u7c7b\u578b<code>float<\/code>\uff0c\u800c<code>d<\/code>\u8868\u793a\u53c2\u6570\u7c7b\u578b\u662f<code>double<\/code>\u3002\u7ecf\u8fc7 <code>name mangling<\/code> \u540e\u53ef\u4ee5\u53d1\u73b0\uff0c\u51fd\u6570\u91cd\u8f7d\u4e0e\u8fd4\u56de\u503c\u7c7b\u578b\u65e0\u5173\uff0c\u4ec5\u4e0e\u51fd\u6570\u540d\u548c\u51fd\u6570\u53c2\u6570\u7c7b\u578b\u76f8\u5173\u3002<\/p>\n<p>\u6ce8\u610f\uff1a\u4e0d\u5fc5\u8fc7\u4e8e\u5173\u6ce8<code>name mangling<\/code>\u672c\u8eab\uff0c\u53ea\u9700\u8981\u77e5\u9053<code>name mangling<\/code>\u8fd9\u4e2a\u673a\u5236\u662f\u4e00\u5957\u547d\u540d\u89c4\u5219\uff0c\u4e3a\u6bcf\u4e2a\u51fd\u6570\u751f\u6210\u552f\u4e00\u7684\u6807\u8bc6\u7b26\u5373\u53ef\uff0c\u4e0d\u5fc5\u7814\u7a76\u89c4\u5219\u672c\u8eab\uff0c\u662f\u600e\u4e48\u547d\u540d\u7684\uff0c\u6bcf\u4e2a\u5355\u8bcd\u662f\u5565\u7f29\u5199\uff0c\u5927\u81f4\u4e86\u89e3\u5373\u53ef\uff0c\u4e0d\u540c\u7684\u7f16\u8bd1\u5668\u89c4\u5219\u90fd\u53ef\u80fd\u4e0d\u540c\u3002<\/p>\n<p>\u76f8\u4fe1\uff0c\u5230\u6b64\uff0c\u4f60\u5e94\u8be5\u660e\u767d\u4e86\u51fd\u6570\u91cd\u8f7d\u600e\u4e48\u56de\u4e8b\uff1a<strong>\u53ea\u4f9d\u8d56\u4e8e\u51fd\u6570\u540d\u53ca\u5176\u53c2\u6570\u7c7b\u578b\uff0c\u4e0e\u8fd4\u56de\u503c\u7c7b\u578b\u65e0\u5173<\/strong>\uff01\uff01\uff01<\/p>\n<h2 id=\"\u6210\u5458\u51fd\u6570\u6307\u9488\">\u6210\u5458\u51fd\u6570\u6307\u9488<\/h2>\n<p><strong>\u95ee\uff1a\u6210\u5458\u51fd\u6570\u6307\u9488\u4e86\u89e3\u4e48\uff1f\u53ef\u4ee5\u8f6c\u6362\u4e3aVoid*\u4e48\uff1f\u4e3a\u4ec0\u4e48\uff1f<\/strong><\/p>\n<p>\u6210\u5458\u51fd\u6570\u6307\u9488\u662f\u6307\u5411\u6210\u5458\u51fd\u6570\u7684\u6307\u9488\u3002\u7531\u4e8e\u6210\u5458\u51fd\u6570\u6307\u9488\u5728\u8c03\u7528\u65f6\u9700\u8981\u63d0\u4f9b\u4e00\u4e2a\u5bf9\u8c61\u7684\u5730\u5740\uff0c\u56e0\u6b64\u5176\u7c7b\u578b\u4e0e\u666e\u901a\u51fd\u6570\u6307\u9488\u4e0d\u540c\u3002\u5728C++\u4e2d\uff0c\u4f7f\u7528\u6210\u5458\u51fd\u6570\u6307\u9488\u65f6\u9700\u8981\u4f7f\u7528\u6307\u5411\u5bf9\u8c61\u7684\u6307\u9488\u6216\u5f15\u7528\u3002<\/p>\n<p>\u6210\u5458\u51fd\u6570\u6307\u9488\u53ef\u4ee5\u8f6c\u6362\u4e3avoid*\uff0c\u4f46\u662f\u8fd9\u4e2a\u8f6c\u6362\u662f\u4e0d\u5b89\u5168\u7684\u3002void\u662f\u4e00\u79cd\u901a\u7528\u6307\u9488\u7c7b\u578b\uff0c\u53ef\u4ee5\u6307\u5411\u4efb\u610f\u7c7b\u578b\u7684\u6570\u636e\uff0c\u800c\u6210\u5458\u51fd\u6570\u6307\u9488\u662f\u4e00\u79cd\u7279\u5b9a\u7c7b\u578b\u7684\u6307\u9488\uff0c\u5176\u6307\u5411\u7684\u662f\u7279\u5b9a\u7684\u6210\u5458\u51fd\u6570\u3002\u56e0\u6b64\uff0c\u5c06\u6210\u5458\u51fd\u6570\u6307\u9488\u8f6c\u6362\u4e3avoid\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7c7b\u578b\u9519\u8bef\u6216\u8bbf\u95ee\u8fdd\u89c4\u3002<\/p>\n<p>\u5728\u8fdb\u884c\u6307\u9488\u7c7b\u578b\u8f6c\u6362\u65f6\uff0c\u5e94\u8be5\u5c3d\u91cf\u907f\u514d\u4f7f\u7528void*\uff0c\u800c\u662f\u4f7f\u7528\u66f4\u5177\u4f53\u7684\u7c7b\u578b\u6765\u4fdd\u8bc1\u7c7b\u578b\u5b89\u5168\u3002\u5982\u679c\u9700\u8981\u5c06\u6210\u5458\u51fd\u6570\u6307\u9488\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u6216\u8fd4\u56de\u503c\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u51fd\u6570\u6a21\u677f\u6216std::function\u6765\u5c01\u88c5\u6210\u5458\u51fd\u6570\u6307\u9488\u3002<\/p>\n<h2 id=\"\u7f16\u8bd1\u8fc7\u7a0b\">\u7f16\u8bd1\u8fc7\u7a0b<\/h2>\n<p><strong>\u95ee:\u63cf\u8ff0\u4e00\u4e0bC\/C++\u4ee3\u7801\u7684\u7f16\u8bd1\u8fc7\u7a0b\uff1f<\/strong><\/p>\n<p>C\/C++\u4ee3\u7801\u7684\u7f16\u8bd1\u8fc7\u7a0b\u662f\u4e00\u4e2a\u76f8\u5bf9\u590d\u6742\u7684\u8fc7\u7a0b\uff0c\u6d89\u53ca\u591a\u4e2a\u9636\u6bb5\u3002\u4ee5\u4e0b\u662fC\/C++\u4ee3\u7801\u7f16\u8bd1\u8fc7\u7a0b\u7684\u4e3b\u8981\u6b65\u9aa4\uff1a<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>\u9884\u5904\u7406\uff08Preprocessing\uff09\n<p>\uff1a<\/p>\n<ul>\n<li>\u7f16\u8bd1\u5668\u9996\u5148\u8bfb\u53d6\u6e90\u4ee3\u7801\u6587\u4ef6\uff08\u5982 <code>.c<\/code> \u6216 <code>.cpp<\/code> \u6587\u4ef6\uff09\u3002<\/li>\n<li>\u9884\u5904\u7406\u5668\uff08preprocessor\uff09\u5904\u7406\u6e90\u4ee3\u7801\u4e2d\u7684\u9884\u5904\u7406\u6307\u4ee4\uff0c\u5982 <code>#include<\/code>\u3001<code>#define<\/code> \u7b49\u3002<\/li>\n<li><code>#include<\/code> \u6307\u4ee4\u544a\u8bc9\u9884\u5904\u7406\u5668\u5c06\u53e6\u4e00\u4e2a\u6587\u4ef6\u7684\u5185\u5bb9\u5305\u542b\u5728\u5f53\u524d\u6587\u4ef6\u4e2d\u3002\u8fd9\u901a\u5e38\u7528\u4e8e\u5305\u542b\u6807\u51c6\u5e93\u6216\u7528\u6237\u81ea\u5b9a\u4e49\u7684\u5934\u6587\u4ef6\u3002<\/li>\n<li><code>#define<\/code> \u6307\u4ee4\u5b9a\u4e49\u5b8f\uff0c\u9884\u5904\u7406\u5668\u4f1a\u5728\u7f16\u8bd1\u524d\u66ff\u6362\u6240\u6709\u5b8f\u5b9a\u4e49\u3002<\/li>\n<li>\u9884\u5904\u7406\u540e\u7684\u4ee3\u7801\u901a\u5e38\u4fdd\u5b58\u4e3a\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\uff0c\u901a\u5e38\u4ee5 <code>.i<\/code> \u6216 <code>.ii<\/code> \u4f5c\u4e3a\u6587\u4ef6\u6269\u5c55\u540d\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u7f16\u8bd1\uff08Compilation\uff09\n<p>\uff1a<\/p>\n<ul>\n<li>\u7ecf\u8fc7\u9884\u5904\u7406\u540e\u7684\u4ee3\u7801\u8fdb\u5165\u7f16\u8bd1\u9636\u6bb5\u3002<\/li>\n<li>\u7f16\u8bd1\u5668\u5c06\u9884\u5904\u7406\u540e\u7684\u4ee3\u7801\u8f6c\u6362\u4e3a\u6c47\u7f16\u8bed\u8a00\u4ee3\u7801\u3002\u8fd9\u4e00\u6b65\u9aa4\u6d89\u53ca\u5230\u8bcd\u6cd5\u5206\u6790\u3001\u8bed\u6cd5\u5206\u6790\u3001\u8bed\u4e49\u5206\u6790\u3001\u4e2d\u95f4\u4ee3\u7801\u751f\u6210\u548c\u76ee\u6807\u4ee3\u7801\u751f\u6210\u7b49\u5b50\u6b65\u9aa4\u3002<\/li>\n<li>\u8bcd\u6cd5\u5206\u6790\u5c06\u6e90\u4ee3\u7801\u5206\u89e3\u4e3a\u4e00\u7cfb\u5217\u7684\u6807\u8bb0\uff08tokens\uff09\u3002<\/li>\n<li>\u8bed\u6cd5\u5206\u6790\u68c0\u67e5\u8fd9\u4e9b\u6807\u8bb0\u662f\u5426\u7b26\u5408\u8bed\u8a00\u7684\u8bed\u6cd5\u89c4\u5219\uff0c\u5e76\u6784\u5efa\u62bd\u8c61\u8bed\u6cd5\u6811\uff08AST\uff09\u3002<\/li>\n<li>\u8bed\u4e49\u5206\u6790\u68c0\u67e5AST\u7684\u8bed\u4e49\uff0c\u786e\u4fdd\u5b83\u4eec\u662f\u6709\u6548\u7684\u3002<\/li>\n<li>\u4e2d\u95f4\u4ee3\u7801\u751f\u6210\u5c06AST\u8f6c\u6362\u4e3a\u4e2d\u95f4\u8868\u793a\u5f62\u5f0f\uff08IR\uff09\u3002<\/li>\n<li>\u76ee\u6807\u4ee3\u7801\u751f\u6210\u5c06IR\u8f6c\u6362\u4e3a\u7279\u5b9a\u4e8e\u5e73\u53f0\u7684\u6c47\u7f16\u8bed\u8a00\u4ee3\u7801\u3002<\/li>\n<li>\u7f16\u8bd1\u540e\u7684\u6c47\u7f16\u4ee3\u7801\u901a\u5e38\u4fdd\u5b58\u4e3a <code>.s<\/code> \u6587\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u6c47\u7f16\uff08Assembly\uff09\n<p>\uff1a<\/p>\n<ul>\n<li>\u6c47\u7f16\u5668\uff08assembler\uff09\u5c06\u6c47\u7f16\u4ee3\u7801\u8f6c\u6362\u4e3a\u673a\u5668\u4ee3\u7801\uff08\u4e5f\u79f0\u4e3a\u76ee\u6807\u4ee3\u7801\uff09\u3002<\/li>\n<li>\u8fd9\u4e00\u6b65\u9aa4\u5c06\u6c47\u7f16\u6307\u4ee4\u8f6c\u6362\u4e3a\u673a\u5668\u53ef\u4ee5\u6267\u884c\u7684\u4e8c\u8fdb\u5236\u6307\u4ee4\u3002<\/li>\n<li>\u6c47\u7f16\u540e\u7684\u673a\u5668\u4ee3\u7801\u901a\u5e38\u4fdd\u5b58\u4e3a <code>.o<\/code> \u6216 <code>.obj<\/code> \u6587\u4ef6\uff0c\u79f0\u4e3a\u76ee\u6807\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u94fe\u63a5\uff08Linking\uff09\n<p>\uff1a<\/p>\n<ul>\n<li>\u94fe\u63a5\u5668\uff08linker\uff09\u5c06\u591a\u4e2a\u76ee\u6807\u6587\u4ef6\u4ee5\u53ca\u5fc5\u8981\u7684\u5e93\u6587\u4ef6\u7ec4\u5408\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u6216\u5171\u4eab\u5e93\u3002<\/li>\n<li>\u5982\u679c\u4ee3\u7801\u4e2d\u6709\u5bf9\u5176\u4ed6\u51fd\u6570\u6216\u53d8\u91cf\u7684\u5f15\u7528\uff08\u4f8b\u5982\uff0c\u6765\u81ea\u6807\u51c6\u5e93\u6216\u5176\u4ed6\u7528\u6237\u5b9a\u4e49\u7684\u6587\u4ef6\uff09\uff0c\u94fe\u63a5\u5668\u4f1a\u627e\u5230\u8fd9\u4e9b\u5f15\u7528\u7684\u5b9a\u4e49\uff0c\u5e76\u5c06\u5b83\u4eec\u5305\u542b\u5728\u6700\u7ec8\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u3002<\/li>\n<li>\u5982\u679c\u627e\u4e0d\u5230\u67d0\u4e9b\u5f15\u7528\u7684\u5b9a\u4e49\uff0c\u94fe\u63a5\u5668\u4f1a\u62a5\u9519\u3002<\/li>\n<li>\u94fe\u63a5\u5b8c\u6210\u540e\uff0c\u751f\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff08\u5982 <code>.out<\/code>\u3001<code>.exe<\/code>\uff09\u6216\u5171\u4eab\u5e93\uff08\u5982 <code>.so<\/code>\u3001<code>.dll<\/code>\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u52a0\u8f7d\u548c\u6267\u884c\uff08Loading and Execution\uff09\n<p>\uff1a<\/p>\n<ul>\n<li>\u5f53\u7528\u6237\u8fd0\u884c\u53ef\u6267\u884c\u6587\u4ef6\u65f6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u5c06\u5176\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u5e76\u8bbe\u7f6e\u5fc5\u8981\u7684\u6267\u884c\u73af\u5883\u3002<\/li>\n<li>CPU\u5f00\u59cb\u6267\u884c\u7a0b\u5e8f\uff0c\u4ece <code>main<\/code> \u51fd\u6570\u5f00\u59cb\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u95ee\uff1a\u4e86\u89e3\u9759\u6001\u5e93\u4e0e\u52a8\u6001\u5e93\u4e48\uff1f\u8bf4\u8bf4\u9759\u6001\u94fe\u63a5\u4e0e\u52a8\u6001\u94fe\u63a5\u7684\u5b9e\u73b0\u601d\u8def<\/strong><\/p>\n<p><strong>\u9759\u6001\u94fe\u63a5\u4e0e\u52a8\u6001\u94fe\u63a5<\/strong><\/p>\n<p><strong>\u9759\u6001\u94fe\u63a5<\/strong>\uff1a<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>\u9759\u6001\u94fe\u63a5\u662f\u6307\u5c06\u9759\u6001\u5e93\u4e2d\u7684\u4ee3\u7801\u76f4\u63a5\u94fe\u63a5\u5230\u76ee\u6807\u7a0b\u5e8f\u4e2d\uff0c\u751f\u6210\u4e00\u4e2a\u5b8c\u6574\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/li>\n<li>\u9759\u6001\u94fe\u63a5\u7684\u5b9e\u73b0\u601d\u8def\u662f\u5728\u7f16\u8bd1\u65f6\uff0c\u5c06\u9759\u6001\u5e93\u4e2d\u7684\u4ee3\u7801\u548c\u76ee\u6807\u7a0b\u5e8f\u7684\u4ee3\u7801\u4e00\u8d77\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/li>\n<li>\u8fd9\u79cd\u94fe\u63a5\u65b9\u5f0f\u751f\u6210\u7684\u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6\u4e0d\u4f9d\u8d56\u5916\u90e8\u5e93\u6587\u4ef6\uff0c\u4f46\u662f\u4f53\u79ef\u8f83\u5927\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u52a8\u6001\u94fe\u63a5<\/strong>\uff1a<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>\u52a8\u6001\u94fe\u63a5\u662f\u6307\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u5c06\u52a8\u6001\u5e93\u4e2d\u7684\u4ee3\u7801\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u5e76\u4e0e\u76ee\u6807\u7a0b\u5e8f\u7684\u4ee3\u7801\u8fdb\u884c\u94fe\u63a5\u3002<\/li>\n<li>\u52a8\u6001\u94fe\u63a5\u7684\u5b9e\u73b0\u601d\u8def\u662f\u5728\u7f16\u8bd1\u65f6\uff0c\u53ea\u5728\u76ee\u6807\u7a0b\u5e8f\u4e2d\u8bb0\u5f55\u4e0b\u6240\u9700\u52a8\u6001\u5e93\u7684\u540d\u79f0\u548c\u4f4d\u7f6e\uff0c\u5e76\u4e0d\u5b9e\u9645\u5305\u542b\u5e93\u4e2d\u7684\u4ee3\u7801\u3002\u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6\uff0c\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u6839\u636e\u8fd9\u4e9b\u8bb0\u5f55\u53bb\u67e5\u627e\u548c\u52a0\u8f7d\u52a8\u6001\u5e93\u3002<\/li>\n<li>\u8fd9\u79cd\u94fe\u63a5\u65b9\u5f0f\u751f\u6210\u7684\u7a0b\u5e8f\u4f53\u79ef\u8f83\u5c0f\uff0c\u4f46\u9700\u8981\u4f9d\u8d56\u5916\u90e8\u5e93\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u9759\u6001\u94fe\u63a5<\/strong>\uff1a\u7f16\u8bd1\u5668\u548c\u6c47\u7f16\u5668\u5c06\u591a\u4e2a\u6587\u4ef6\uff08\u6a21\u5757\uff09\u751f\u6210\u591a\u4e2a<strong>\u53ef\u91cd\u5b9a\u4f4d\u7684\u76ee\u6807\u6587\u4ef6<\/strong>\uff0c<strong>\u9759\u6001\u94fe\u63a5\u5668<\/strong>\u5728\u94fe\u63a5\u65f6\u5c06\u591a\u4e2a\u53ef\u91cd\u5b9a\u4f4d\u76ee\u6807\u6587\u4ef6\u94fe\u63a5\u6210\u53ef\u6267\u884c\u7684\u6587\u4ef6\uff08exe\uff0c.out\u6587\u4ef6 ELF\u683c\u5f0f\uff09<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040101.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040101.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" \/><\/div><\/p>\n<p><strong>\u9759\u6001\u5e93\u6587\u4ef6<\/strong>\u53ef\u4ee5\u5728\u9759\u6001\u94fe\u63a5\u65f6\u548c\u5176\u4ed6\u53ef\u91cd\u5b9a\u4f4d\u76ee\u6807\u6587\u4ef6\u4e00\u540c\u94fe\u63a5\u6210\u53ef\u6267\u884c\u76ee\u6807\u6587\u4ef6\u3002<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040102.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040102.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" \/><\/div><\/p>\n<p><strong>\u52a8\u6001\u94fe\u63a5<\/strong>\uff1a\u52a8\u6001\u94fe\u63a5\u5668\u9700\u8981\u5728\u94fe\u63a5\u65f6\u5148\u901a\u8fc7\u9759\u6001\u8fde\u63a5\u5668\u4f20\u5165\u4e00\u4e9b\u91cd\u5b9a\u4f4d\u548c\u7b26\u53f7\u4fe1\u606f\uff0c\u540e\u7eed\u5728\u53ef\u6267\u884c\u6587\u4ef6\u52a0\u8f7d\u6216\u8005\u8fd0\u884c\u7684\u65f6\u5019\u5148\u52a0\u8f7d\u52a8\u6001\u94fe\u63a5\u5668\uff08.interp\u8282\u4e2d\u548c\u5305\u542b\u52a8\u6001\u8fde\u63a5\u5668\u7684\u8def\u5f84\uff0c\u4ed6\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u5171\u4eab\u5e93\uff09\uff0c\u968f\u540e\u6839\u636e\u91cd\u5b9a\u4f4d\u7b49\u4fe1\u606f\u5c06\u76ee\u6807\u52a8\u6001\u5e93\u6587\u4ef6\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040103.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040103.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" \/><\/div><\/p>\n<p><strong>\u9759\u6001\u5e93<\/strong>\uff1a<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>\u9759\u6001\u5e93\u5728\u7a0b\u5e8f\u7f16\u8bd1\u65f6\u5c31\u4f1a\u88ab\u94fe\u63a5\u5230\u76ee\u6807\u7a0b\u5e8f\u4e2d\uff0c\u6210\u4e3a\u76ee\u6807\u7a0b\u5e8f\u7684\u4e00\u90e8\u5206\u3002<\/li>\n<li>\u9759\u6001\u5e93\u4e2d\u7684\u4ee3\u7801\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u4f1a\u88ab\u5b8c\u5168\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002<\/li>\n<li>\u9759\u6001\u5e93\u6587\u4ef6\u901a\u5e38\u5177\u6709<code>.a<\/code>\uff08\u5728Unix-like\u7cfb\u7edf\uff09\u6216<code>.lib<\/code>\uff08\u5728Windows\uff09\u7684\u6269\u5c55\u540d\u3002<\/li>\n<li>\u4f18\u70b9\uff1a\u4e0d\u9700\u8981\u5728\u8fd0\u884c\u65f6\u67e5\u627e\u5e93\u6587\u4ef6\uff0c\u7a0b\u5e8f\u8fd0\u884c\u7a33\u5b9a\uff0c\u4e0d\u4f1a\u53d7\u5230\u5e93\u6587\u4ef6\u66f4\u65b0\u7684\u5f71\u54cd\u3002<\/li>\n<li>\u7f3a\u70b9\uff1a\u751f\u6210\u7684\u7a0b\u5e8f\u4f53\u79ef\u8f83\u5927\uff0c\u5982\u679c\u591a\u4e2a\u7a0b\u5e8f\u90fd\u4f7f\u7528\u4e86\u540c\u4e00\u4e2a\u9759\u6001\u5e93\uff0c\u90a3\u4e48\u6bcf\u4e2a\u7a0b\u5e8f\u90fd\u4f1a\u5305\u542b\u4e00\u4efd\u5e93\u4ee3\u7801\uff0c\u9020\u6210\u7a7a\u95f4\u6d6a\u8d39\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u52a8\u6001\u5e93<\/strong>\uff1a<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>\u52a8\u6001\u5e93\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u624d\u88ab\u52a0\u8f7d\uff0c\u800c\u4e0d\u662f\u5728\u7f16\u8bd1\u65f6\u3002<\/li>\n<li>\u52a8\u6001\u5e93\u4e2d\u7684\u4ee3\u7801\u53ea\u6709\u5728\u7a0b\u5e8f\u9700\u8981\u65f6\u624d\u4f1a\u88ab\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002<\/li>\n<li>\u52a8\u6001\u5e93\u6587\u4ef6\u901a\u5e38\u5177\u6709<code>.so<\/code>\uff08\u5728Unix-like\u7cfb\u7edf\uff09\u6216<code>.dll<\/code>\uff08\u5728Windows\uff09\u7684\u6269\u5c55\u540d\u3002<\/li>\n<li>\u4f18\u70b9\uff1a\u7a0b\u5e8f\u4f53\u79ef\u8f83\u5c0f\uff0c\u591a\u4e2a\u7a0b\u5e8f\u53ef\u4ee5\u5171\u4eab\u540c\u4e00\u4e2a\u52a8\u6001\u5e93\uff0c\u8282\u7701\u7a7a\u95f4\u3002\u5e93\u6587\u4ef6\u66f4\u65b0\u540e\uff0c\u6240\u6709\u4f7f\u7528\u8be5\u5e93\u7684\u7a0b\u5e8f\u90fd\u80fd\u7acb\u5373\u4eab\u53d7\u5230\u66f4\u65b0\u5e26\u6765\u7684\u597d\u5904\u3002<\/li>\n<li>\u7f3a\u70b9\uff1a\u8fd0\u884c\u65f6\u9700\u8981\u67e5\u627e\u5e93\u6587\u4ef6\uff0c\u5982\u679c\u5e93\u6587\u4ef6\u7f3a\u5931\u6216\u7248\u672c\u4e0d\u5339\u914d\uff0c\u7a0b\u5e8f\u53ef\u80fd\u65e0\u6cd5\u6b63\u5e38\u8fd0\u884c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u95ee\uff1a\u77e5\u9053\u5185\u90e8\u94fe\u63a5\u4e0e\u5916\u90e8\u94fe\u63a5\u4e48\uff1f<\/strong><\/p>\n<p>\u5728\u7f16\u8bd1\u539f\u7406\u4e2d\uff0c\u5185\u90e8\u94fe\u63a5\u548c\u5916\u90e8\u94fe\u63a5\u4e3b\u8981\u6d89\u53ca\u5230\u7a0b\u5e8f\u4e2d\u7684\u7b26\u53f7\u6216\u5b9a\u4e49\u5728\u94fe\u63a5\u8fc7\u7a0b\u4e2d\u7684\u53ef\u89c1\u6027\u548c\u53ef\u8bbf\u95ee\u6027\u3002<\/p>\n<p><strong>\u5185\u90e8\u94fe\u63a5<\/strong>\uff1a<\/p>\n<p>\u5185\u90e8\u94fe\u63a5\u610f\u5473\u7740\u4e00\u4e2a\u5b9a\u4e49\u6216\u7b26\u53f7\u7684\u8bbf\u95ee\u53d7\u5230\u5f53\u524d\u7f16\u8bd1\u5355\u5143\u7684\u9650\u5236\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u8fd9\u4e2a\u5b9a\u4e49\u6216\u7b26\u53f7\u5bf9\u4e8e\u4efb\u4f55\u5176\u4ed6\u7f16\u8bd1\u5355\u5143\u90fd\u662f\u4e0d\u53ef\u89c1\u7684\u3002\u5728\u94fe\u63a5\u8fc7\u7a0b\u4e2d\uff0c\u5176\u4ed6\u7f16\u8bd1\u5355\u5143\u65e0\u6cd5\u94fe\u63a5\u5230\u8fd9\u4e2a\u5b9a\u4e49\u6216\u7b26\u53f7\u3002\u8fd9\u901a\u5e38\u9002\u7528\u4e8e\u9759\u6001\uff08static\uff09\u5168\u5c40\u53d8\u91cf\u7684\u5b9a\u4e49\u3001\u9759\u6001\u81ea\u7531\u51fd\u6570\u7684\u5b9a\u4e49\u3001\u9759\u6001\u53cb\u5143\u51fd\u6570\u7684\u5b9a\u4e49\u3001\u7c7b\u7684\u5b9a\u4e49\u3001\u5185\u8054\u51fd\u6570\u5b9a\u4e49\u3001Union\u5171\u540c\u4f53\u5b9a\u4e49\u3001const\u5e38\u91cf\u5b9a\u4e49\u3001\u679a\u4e3e\u7c7b\u578b\u5b9a\u4e49\u7b49\u3002\u5185\u90e8\u94fe\u63a5\u7684\u4e00\u4e2a\u5178\u578b\u4f8b\u5b50\u662f\u7c7b\u7684\u5b9a\u4e49\uff0c\u56e0\u4e3a\u7c7b\u7684\u63cf\u8ff0\u901a\u5e38\u662f\u4e00\u4e2a\u5b9a\u4e49\uff0c\u5e76\u4e14\u5b83\u53ea\u5728\u5b9a\u4e49\u5b83\u7684\u7f16\u8bd1\u5355\u5143\u5185\u90e8\u53ef\u89c1\u3002<\/p>\n<p><strong>\u5916\u90e8\u94fe\u63a5<\/strong>\uff1a<\/p>\n<p>\u5916\u90e8\u94fe\u63a5\u5219\u662f\u6307\u4e00\u4e2a\u5b9a\u4e49\u6216\u7b26\u53f7\u5728\u94fe\u63a5\u65f6\u53ef\u4ee5\u88ab\u5176\u4ed6\u7f16\u8bd1\u5355\u5143\u8bbf\u95ee\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u8fd9\u4e2a\u5b9a\u4e49\u6216\u7b26\u53f7\u4e0d\u662f\u5c40\u90e8\u7684\uff0c\u5b83\u53ef\u4ee5\u548c\u522b\u7684\u7f16\u8bd1\u5355\u5143\u4ea4\u4e92\u3002\u5982\u679c\u4e00\u4e2a\u540d\u79f0\u5728\u8fde\u63a5\u65f6\u53ef\u4ee5\u548c\u5176\u4ed6\u7684\u7f16\u8bd1\u5355\u5143\u4ea4\u4e92\uff0c\u5219\u8fd9\u4e2a\u540d\u79f0\u5177\u6709\u5916\u90e8\u8fde\u63a5\u3002\u8fd9\u901a\u5e38\u7528\u4e8e\u5168\u5c40\u53d8\u91cf\u6216\u51fd\u6570\u7684\u5b9a\u4e49\uff0c\u5b83\u4eec\u5728\u6574\u4e2a\u7a0b\u5e8f\u4e2d\u90fd\u662f\u53ef\u89c1\u7684\uff0c\u53ef\u4ee5\u88ab\u5176\u4ed6\u7f16\u8bd1\u5355\u5143\u5f15\u7528\u3002<\/p>\n<p>\u94fe\u63a5\u5668\u5728\u94fe\u63a5\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u6839\u636e\u8fd9\u4e9b\u94fe\u63a5\u5c5e\u6027\u6765\u786e\u5b9a\u5982\u4f55\u5c06\u5404\u4e2a\u7f16\u8bd1\u5355\u5143\u4e2d\u7684\u7b26\u53f7\u94fe\u63a5\u8d77\u6765\uff0c\u751f\u6210\u6700\u7ec8\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u5185\u90e8\u94fe\u63a5\u7684\u7b26\u53f7\u5728\u94fe\u63a5\u65f6\u4e0d\u4f1a\u88ab\u5bfc\u51fa\u5230\u5176\u4ed6\u7f16\u8bd1\u5355\u5143\uff0c\u800c\u5916\u90e8\u94fe\u63a5\u7684\u7b26\u53f7\u5219\u4f1a\u88ab\u5bfc\u51fa\uff0c\u4ee5\u4fbf\u5176\u4ed6\u7f16\u8bd1\u5355\u5143\u53ef\u4ee5\u5f15\u7528\u5b83\u4eec\u3002<\/p>\n<h2 id=\"extern\u548cstatic\">extern\u548cstatic<\/h2>\n<p><strong>\u95ee\uff1aextern\u4e0estatic<\/strong><\/p>\n<p>\u5728C\u8bed\u8a00\u4e2d\uff0c<code>extern<\/code>\u548c<code>static<\/code>\u90fd\u662f\u975e\u5e38\u91cd\u8981\u7684\u5173\u952e\u5b57\uff0c\u5b83\u4eec\u4e0e\u53d8\u91cf\u7684\u94fe\u63a5\u6027\u548c\u53ef\u89c1\u6027\u7d27\u5bc6\u76f8\u5173\u3002<\/p>\n<p><strong>extern<\/strong><\/p>\n<p><code>extern<\/code>\u5173\u952e\u5b57\u7528\u4e8e\u58f0\u660e\u5168\u5c40\u53d8\u91cf\u6216\u51fd\u6570\u7684\u5916\u90e8\u94fe\u63a5\u3002\u5176\u4e3b\u8981\u4f5c\u7528\u662f\u6269\u5c55\u53d8\u91cf\u548c\u51fd\u6570\u7684\u53ef\u89c1\u6027\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u5f53\u4f60\u5728\u4e00\u4e2a\u6e90\u6587\u4ef6\u4e2d\u58f0\u660e\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf\u6216\u51fd\u6570\u4e3a<code>extern<\/code>\u65f6\uff0c\u4f60\u5b9e\u9645\u4e0a\u662f\u5728\u544a\u8bc9\u7f16\u8bd1\u5668\uff1a\u201c\u8fd9\u4e2a\u53d8\u91cf\u6216\u51fd\u6570\u662f\u5728\u5176\u4ed6\u5730\u65b9\u5b9a\u4e49\u7684\uff0c\u6211\u8981\u5728\u8fd9\u91cc\u5f15\u7528\u5b83\u201d\u3002\u8fd9\u6837\uff0c\u7f16\u8bd1\u5668\u5c31\u77e5\u9053\u5728\u94fe\u63a5\u65f6\u9700\u8981\u67e5\u627e\u8fd9\u4e2a\u53d8\u91cf\u6216\u51fd\u6570\u7684\u5b9a\u4e49\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5047\u8bbe\u4f60\u6709\u4e24\u4e2a\u6e90\u6587\u4ef6\uff1a<code>main.c<\/code>\u548c<code>global.c<\/code>\u3002\u5982\u679c\u4f60\u5728<code>global.c<\/code>\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf<code>globalVar<\/code>\uff0c\u7136\u540e\u5728<code>main.c<\/code>\u4e2d\u4f7f\u7528<code>extern<\/code>\u6765\u58f0\u660e\u5b83\uff0c\u90a3\u4e48\u7f16\u8bd1\u5668\u5c31\u77e5\u9053<code>globalVar<\/code>\u5728<code>global.c<\/code>\u4e2d\u5b9a\u4e49\uff0c\u5e76\u5728\u94fe\u63a5\u65f6\u5c06\u5176\u94fe\u63a5\u5230<code>main.c<\/code>\u3002<\/p>\n<p>\u540c\u6837\u7684\uff0c\u4f60\u4e5f\u53ef\u4ee5\u7528<code>extern<\/code>\u6765\u58f0\u660e\u5916\u90e8\u51fd\u6570\u3002\u8fd9\u610f\u5473\u7740\u4f60\u53ef\u4ee5\u5728\u4e00\u4e2a\u6587\u4ef6\u4e2d\u5b9a\u4e49\u51fd\u6570\uff0c\u7136\u540e\u5728\u5176\u4ed6\u6587\u4ef6\u4e2d\u58f0\u660e\u5e76\u4f7f\u7528\u5b83\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c<code>extern<\/code>\u58f0\u660e\u5e76\u4e0d\u662f\u5b9a\u4e49\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5b83\u5e76\u4e0d\u5206\u914d\u5b58\u50a8\u7a7a\u95f4\u3002\u5b83\u53ea\u662f\u544a\u8bc9\u7f16\u8bd1\u5668\u8fd9\u4e2a\u53d8\u91cf\u6216\u51fd\u6570\u5728\u5176\u4ed6\u5730\u65b9\u5b9a\u4e49\uff0c\u5e76\u9700\u8981\u94fe\u63a5\u3002<\/p>\n<p><strong>static<\/strong><\/p>\n<p><code>static<\/code>\u5173\u952e\u5b57\u5728C\u8bed\u8a00\u4e2d\u6709\u591a\u79cd\u7528\u6cd5\uff0c\u5b83\u53ef\u4ee5\u7528\u6765\u4fee\u9970\u5c40\u90e8\u53d8\u91cf\u3001\u5168\u5c40\u53d8\u91cf\u548c\u51fd\u6570\u3002<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>\u5f53<code>static<\/code>\u4fee\u9970\u5c40\u90e8\u53d8\u91cf\u65f6\uff0c\u8be5\u53d8\u91cf\u7684\u751f\u547d\u5468\u671f\u88ab\u5ef6\u957f\u81f3\u6574\u4e2a\u7a0b\u5e8f\u7684\u6267\u884c\u671f\u95f4\uff0c\u4f46\u5176\u53ef\u89c1\u6027\u4ecd\u9650\u4e8e\u5b9a\u4e49\u5b83\u7684\u4ee3\u7801\u5757\u3002\u8fd9\u610f\u5473\u7740\u8be5\u53d8\u91cf\u53ea\u4f1a\u5728\u9996\u6b21\u8fdb\u5165\u5176\u4f5c\u7528\u57df\u65f6\u88ab\u521d\u59cb\u5316\u4e00\u6b21\u3002<\/li>\n<li>\u5f53<code>static<\/code>\u4fee\u9970\u5168\u5c40\u53d8\u91cf\u65f6\uff0c\u8be5\u53d8\u91cf\u7684\u53ef\u89c1\u6027\u88ab\u9650\u5236\u5728\u5b9a\u4e49\u5b83\u7684\u6e90\u6587\u4ef6\u4e2d\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u8fd9\u4e2a\u5168\u5c40\u53d8\u91cf\u53ea\u80fd\u88ab\u672c\u6587\u4ef6\u4e2d\u7684\u51fd\u6570\u8bbf\u95ee\uff0c\u5176\u4ed6\u6e90\u6587\u4ef6\u65e0\u6cd5\u76f4\u63a5\u8bbf\u95ee\u5b83\u3002\u5373\u4f7f\u4f60\u5728\u5176\u4ed6\u6e90\u6587\u4ef6\u4e2d\u4f7f\u7528<code>extern<\/code>\u6765\u58f0\u660e\u5b83\uff0c\u7f16\u8bd1\u5668\u4e5f\u4f1a\u62a5\u9519\uff0c\u56e0\u4e3a\u5b83\u5728\u5176\u4ed6\u6587\u4ef6\u4e2d\u662f\u4e0d\u53ef\u89c1\u7684\u3002<\/li>\n<li>\u5f53<code>static<\/code>\u4fee\u9970\u51fd\u6570\u65f6\uff0c\u60c5\u51b5\u4e0e\u4fee\u9970\u5168\u5c40\u53d8\u91cf\u7c7b\u4f3c\uff0c\u5373\u8be5\u51fd\u6570\u7684\u4f5c\u7528\u57df\u88ab\u9650\u5236\u5728\u5b9a\u4e49\u5b83\u7684\u6e90\u6587\u4ef6\u4e2d\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2 id=\"delegate\">delegate<\/h2>\n<p><strong>\u95ee\uff1adelegate\u662f\u4ec0\u4e48\uff1f\u5b9e\u73b0\u601d\u8def\uff1f\u4e0eevent\u7684\u533a\u522b\uff1f<\/strong><\/p>\n<p>\u4ee3\u7406\u7b80\u5355\u6765\u8bf4\u5c31\u662f\u8ba9\u5bf9\u8c61B\u53bb\u4ee3\u7406A\u6267\u884cA\u672c\u8eab\u7684\u64cd\u4f5c\uff0c\u672c\u8d28\u4e0a\u5c31\u662f\u901a\u8fc7\u6307\u5411\u5176\u4ed6\u6210\u5458\u51fd\u6570\u6216\u8005\u5168\u5c40\u51fd\u6570\u7684\u51fd\u6570\u6307\u9488\u53bb\u4ee3\u7406\u6267\u884c\u3002\u800c\u51fd\u6570\u6307\u9488\u6709\u4e24\u79cd\uff0c\u6210\u5458\u51fd\u6570\u6307\u9488\u4e0e\u666e\u901a\u7684\u51fd\u6570\u6307\u9488\uff0c\u6211\u4eec\u4e00\u822c\u5c31\u662f\u901a\u8fc7\u5bf9\u8fd9\u4e24\u79cd\u6307\u9488\u7684\u5c01\u88c5\u6765\u5b9e\u73b0\u4ee3\u7406\u7684\u6548\u679c\u3002\u5e38\u89c1\u7684\u5b9e\u73b0\u65b9\u5f0f\u6709\u4e24\u79cd\uff0c\u4e00\u79cd\u662f\u901a\u8fc7\u591a\u6001\u63a5\u53e3\uff0c\u53e6\u4e00\u79cd\u662f\u901a\u8fc7\u5b8f\u3002\u4ee3\u7406\u4e5f\u5206\u4e3a\u5355\u64ad\u4ee3\u7406\u4e0e\u591a\u64ad\u4ee3\u7406\uff0c\u5355\u64ad\u5c31\u662f\u4e00\u4e2a\u8c03\u7528\u53ea\u4ee3\u7406\u6267\u884c\u4e00\u4e2a\u51fd\u6570\u529f\u80fd\uff0c\u591a\u64ad\u4ee3\u7406\u5c31\u662f\u4e00\u4e2a\u8c03\u7528\u53ef\u4ee5\u7ed1\u5b9a\u591a\u4e2a\u4ee3\u7406\u51fd\u6570\uff0c\u53ef\u4ee5\u89e6\u53d1\u591a\u4e2a\u4ee3\u7406\u7684\u51fd\u6570\u64cd\u4f5c\u3002<br \/>\nEvent\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u591a\u64addelegate\uff0c\u53ea\u6709\u58f0\u660e\u4e8b\u4ef6\u7684\u7c7b\u53ef\u4ee5\u8c03\u7528\u4e8b\u4ef6\u7684\u89e6\u53d1\u64cd\u4f5c\u3002\u6700\u5e38\u89c1\u7684\u4e5f\u5bb9\u6613\u7406\u89e3\u7684\u5c31\u662fMFC\u91cc\u9762\u7684\u6309\u94ae\u7684\u9f20\u6807\u70b9\u51fb\u4e8b\u4ef6\u4e86\uff0c\u4ed6\u7684\u8c03\u7528\u53ea\u80fd\u5728Button\u91cc\u9762\u53bb\u6267\u884c\u3002<\/p>\n<h2 id=\"template\">Template<\/h2>\n<p><strong>\u95ee\uff1a\u4f7f\u7528\u8fc7\u6a21\u677f\u4e48\uff1f\u4e86\u89e3\u54ea\u4e9b\u7279\u6027\uff1f<\/strong><\/p>\n<p>\u6a21\u677f\u5206\u4e3a\u51fd\u6570\u6a21\u677f\u4e0e\u7c7b\u6a21\u677f\uff0c\u5176\u6839\u672c\u76ee\u7684\u662f\u5c06\u7c7b\u578b\u201c\u53c2\u6570\u5316\u201d\uff0c\u5b9e\u73b0\u7f16\u8bd1\u65f6\u7684\u201c\u52a8\u6001\u5316\u201d\uff0c\u907f\u514d\u91cd\u590d\u4ee3\u7801\u7684\u4e66\u5199\u3002\u53e6\u4e00\u79cd\u8fd0\u884c\u65f6\u7684\u201c\u52a8\u6001\u5316\u201d\u5c31\u662f\u591a\u6001\u3002<\/p>\n<p>\u6a21\u677f\u4f7f\u7528\u5e38\u89c1\u7684\u7279\u6027\u6709\u201c\u7279\u5316\u201d\uff0c\u201c\u504f\u7279\u5316\u201d\uff0c\u201c\u975e\u7c7b\u578b\u6a21\u677f\u53c2\u6570\u201d\uff0c\u201c\u8bbe\u7f6e\u6a21\u677f\u53c2\u6570\u9ed8\u8ba4\u7c7b\u578b\u201d\uff0c\u201c\u6a21\u677f\u4e2d\u7684typename\u7684\u4f7f\u7528\u201d\uff0c\u201c\u53cc\u91cd\u6a21\u677f\u53c2\u6570Template Template Parameters\u201d\uff0c\u201c\u6210\u5458\u6a21\u677fMember Template\u201d\uff0c\u7406\u89e3\u8fd9\u4e9b\u5185\u5bb9\u6211\u4eec\u5c31\u57fa\u672c\u4e0a\u53ef\u4ee5\u770bSTL\u6807\u51c6\u5e93\u4e86\u3002<\/p>\n<p>\u5f53\u7136\u53ef\u4ee5\uff0c\u4ee5\u4e0b\u662f\u5173\u4e8e\u8fd9\u4e9b\u6a21\u677f\u7279\u6027\u7684\u5177\u4f53\u4f8b\u5b50\uff1a<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>\u7279\u5316 (Specialization)<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u5b8c\u5168\u7279\u5316<\/strong>\uff1a<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u901a\u7528\u7684\u6a21\u677f\u7c7b<code>template&lt;typename T&gt; class MyArray<\/code>\uff0c\u4f46\u6709\u65f6\u6211\u4eec\u60f3\u4e3a<code>int<\/code>\u7c7b\u578b\u63d0\u4f9b\u7279\u5b9a\u7684\u5b9e\u73b0\u3002<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">template&lt;typename T&gt;  \nclass MyArray {  \n    \/\/ \u901a\u7528\u5b9e\u73b0  \n};  \n  \ntemplate&lt;&gt;  \nclass MyArray&lt;int&gt; {  \n    \/\/ \u4e13\u4e3aint\u7c7b\u578b\u5b9e\u73b0\u7684\u7248\u672c  \n};\n<\/code><\/pre>\n<p><strong>\u90e8\u5206\u7279\u5316<\/strong>\uff1a<\/p>\n<p>\u5f53\u6211\u4eec\u60f3\u5bf9\u6a21\u677f\u53c2\u6570\u4e2d\u7684\u67d0\u4e9b\u7c7b\u578b\u8fdb\u884c\u7279\u5316\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u90e8\u5206\u7279\u5316\u3002<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">template&lt;typename T1, typename T2&gt;  \nclass MyPair {  \n    \/\/ \u901a\u7528\u5b9e\u73b0  \n};  \n  \ntemplate&lt;typename T&gt;  \nclass MyPair&lt;T*, int&gt; {  \n    \/\/ \u4e13\u4e3aT*\u548cint\u7ec4\u5408\u7684\u7279\u5316\u7248\u672c  \n};\n<\/code><\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ol start=\"2\">\n<li>\u975e\u7c7b\u578b\u6a21\u677f\u53c2\u6570 (Non-Type Template Parameters)<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\" lang=\"cpp\">template&lt;typename T, int N&gt;  \nclass StaticArray {  \npublic:  \n    T array[N];  \n      \n    void fill(T value) {  \n        for(int i = 0; i &lt; N; ++i) {  \n            array[i] = value;  \n        }  \n    }  \n};  \n  \nint main() {  \n    StaticArray&lt;int, 10&gt; arr;  \n    arr.fill(5);  \n    \/\/ ...  \n}\n<\/code><\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ol start=\"3\">\n<li>\u8bbe\u7f6e\u6a21\u677f\u53c2\u6570\u9ed8\u8ba4\u7c7b\u578b (Default Template Parameters)<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\" lang=\"cpp\">template&lt;typename T = int&gt;  \nclass DefaultTypeClass {  \n    T value;  \n    \/\/ ...  \n};  \n  \nint main() {  \n    DefaultTypeClass&lt;&gt; obj1; \/\/ T\u9ed8\u8ba4\u4e3aint  \n    DefaultTypeClass&lt;double&gt; obj2; \/\/ \u660e\u786e\u6307\u5b9aT\u4e3adouble  \n    \/\/ ...  \n}\n<\/code><\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ol start=\"4\">\n<li>\u6a21\u677f\u4e2d\u7684typename\u7684\u4f7f\u7528<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\" lang=\"cpp\">template&lt;typename T&gt;  \nclass MyClass {  \n    typename T::NestedType nestedObj; \/\/ \u4f7f\u7528typename\u8868\u660eNestedType\u662f\u4e00\u4e2a\u7c7b\u578b  \n    \/\/ ...  \n};\n<\/code><\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ol start=\"5\">\n<li>\u53cc\u91cd\u6a21\u677f\u53c2\u6570 (Template Template Parameters)<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\" lang=\"cpp\">template&lt;template&lt;typename&gt; class Container, typename T&gt;  \nclass Wrapper {  \n    Container&lt;T&gt; data;  \n    \/\/ ...  \n};  \n  \nint main() {  \n    Wrapper&lt;std::vector, int&gt; wrapper; \/\/ \u4f7f\u7528std::vector&lt;int&gt;\u4f5c\u4e3a\u5185\u90e8\u5bb9\u5668  \n    \/\/ ...  \n}\n<\/code><\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ol start=\"6\">\n<li>\u6210\u5458\u6a21\u677f (Member Templates)<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\" lang=\"cpp\">class MyClass {  \npublic:  \n    template&lt;typename T&gt;  \n    void setValue(T value) {  \n        \/\/ \u57fa\u4e8eT\u7c7b\u578b\u7684\u5904\u7406  \n    }  \n    \/\/ ...  \n};  \n  \nint main() {  \n    MyClass obj;  \n    obj.setValue(5); \/\/ \u8c03\u7528setValue&lt;int&gt;(int)  \n    obj.setValue(3.14); \/\/ \u8c03\u7528setValue&lt;double&gt;(double)  \n    \/\/ ...  \n}\n<\/code><\/pre>\n<p><strong>\u95ee\uff1a\u6a21\u677f\u4ee3\u7801\u5982\u4f55\u7ec4\u7ec7\uff1f\u6a21\u677f\u7684\u7f16\u8bd1\uff08\u4ee5\u53ca\u5b9e\u4f8b\u5316\uff09\u8fc7\u7a0b<\/strong><\/p>\n<p>\u4e00\u822c\u6765\u8bf4\uff0c\u6a21\u677f\u7c7b\u7684\u58f0\u660e\u4e0e\u5b9a\u4e49\u4e0d\u50cf\u666e\u901a\u7c7b\u90a3\u6837\u62c6\u5206\u6210.h\u548ccpp\uff0c\u800c\u662f\u8981\u5168\u90e8\u653e\u5728\u5934\u6587\u4ef6\u91cc\u9762\uff08\u6216\u8005\u5b9a\u4e49\u653e\u5728\u4f7f\u7528\u5230\u6a21\u677f\u7684.cpp\u91cc\uff09\uff0c\u5426\u5219\u4f1a\u53d1\u751f\u7f16\u8bd1\u9519\u8bef\u3002\u4e3a\u4ec0\u4e48\uff1f\u56e0\u4e3a\u6a21\u677f\u51fd\u6570\u6240\u5728\u7684cpp\u4e0d\u80fd\u76f4\u63a5\u7f16\u8bd1\u6210\u76f8\u5e94\u7684\u4e8c\u8fdb\u5236\u4ee3\u7801\uff0c\u4ed6\u5e76\u4e0d\u77e5\u9053\u6a21\u677f\u53c2\u6570\u662f\u4ec0\u4e48\uff0c\u6240\u4ee5\u9700\u8981\u4e00\u4e2a\u201c\u5b9e\u4f8b\u5316\u201d\u7684\u8fc7\u7a0b\u3002\u7b80\u5355\u6765\u8bf4\uff0cC++\u6807\u51c6\u89c4\u5b9a\uff0c\u5982\u679c\u4e00\u4e2acpp\u91cc\u9762\u6ca1\u6709\u4efb\u4f55\u663e\u793a\u8c03\u7528\u8fc7\u6a21\u677f\u51fd\u6570\uff08\u6216\u8005\u4f7f\u7528\u7c7b\u6a21\u677f\uff09\u7684\u8bed\u53e5\uff0c\u5c31\u4e0d\u4f1a\u751f\u6210\u771f\u6b63\u7684\u62e5\u6709\u786e\u5207\u7c7b\u578b\u7684\u7c7b\u7684\u5b9a\u4e49\uff0c\u8fdb\u800c\u5c31\u4e0d\u4f1a\u751f\u6210\u4efb\u4f55\u4e8c\u8fdb\u5236\u4ee3\u7801\uff0c\u6240\u4ee5\u5176\u4ed6cpp\u4e5f\u65e0\u6cd5\u94fe\u63a5\u5230\u53ea\u5305\u542b\u5b9a\u4e49\u7684.cpp\u6587\u4ef6\u3002\u4e0b\u9762\u7684\u4f8b\u5b50\u5c31\u4f1a\u7f16\u8bd1\u62a5\u9519\uff0c\u9664\u4e86\u628atemplate.cpp\u653e\u5230\u5934\u6587\u4ef6\u91cc\u9762\uff0c\u8fd9\u91cc\u653e\u5230main.cpp\u4e5f\u662f\u53ef\u4ee5\u7684<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">\/\/-------------template.h----------------\/\/ \ntemplate&lt;typename T&gt; \nclass TemTest \n{ \n  public: \n    void TestFun(); \n}; \n\/\/------------template.cpp-------------\/\/ \n#include \u201ctemplate.h\u201d \ntemplate&lt;class T&gt; \nvoid TemTest &lt;T&gt;::TestFun() \/\/\u5b9a\u4e49\uff0c\u4f46\u662f\u4e0d\u4f1a\u751f\u6210\u4e8c\u8fdb\u5236\u6587\u4ef6\n{ \n  .....\n} \n\/\/---------------main.cpp---------------\/\/ \n#include \u201ctemplate.h\u201d \nint main() \n{ \n  TemTest&lt;int&gt; t; \n  t. TestFun(); \n}\n<\/code><\/pre>\n<p>\u4f60\u7684\u89e3\u91ca\u975e\u5e38\u51c6\u786e\uff0c\u5173\u4e8e\u6a21\u677f\u7c7b\u548c\u6a21\u677f\u51fd\u6570\u7684\u7f16\u8bd1\u548c\u94fe\u63a5\u8fc7\u7a0b\uff0c\u786e\u5b9e\u4e0e\u666e\u901a\u7684\u7c7b\u548c\u51fd\u6570\u6709\u6240\u4e0d\u540c\u3002\u4e0b\u9762\u6211\u5c06\u8be6\u7ec6\u89e3\u91ca\u539f\u56e0\uff1a<\/p>\n<p><strong>\u6a21\u677f\u7684\u7f16\u8bd1\u7279\u6027<\/strong><\/p>\n<p>\u5728C++\u4e2d\uff0c\u6a21\u677f\u7c7b\u548c\u6a21\u677f\u51fd\u6570\u5e76\u4e0d\u662f\u771f\u6b63\u7684\u4ee3\u7801\uff0c\u800c\u662f\u4ee3\u7801\u751f\u6210\u5668\u3002\u5f53\u4f60\u7f16\u5199\u4e00\u4e2a\u6a21\u677f\u65f6\uff0c\u4f60\u5b9e\u9645\u4e0a\u662f\u5728\u544a\u8bc9\u7f16\u8bd1\u5668\u5982\u4f55\u6839\u636e\u63d0\u4f9b\u7684\u7c7b\u578b\u53c2\u6570\u6765\u751f\u6210\u5177\u4f53\u7684\u7c7b\u6216\u51fd\u6570\u3002\u7136\u800c\uff0c\u5728\u7f16\u8bd1\u6a21\u677f\u5b9a\u4e49\u7684\u6587\u4ef6\u65f6\uff08\u4f8b\u5982<code>.cpp<\/code>\u6587\u4ef6\uff09\uff0c\u7f16\u8bd1\u5668\u5e76\u4e0d\u4f1a\u751f\u6210\u4efb\u4f55\u5b9e\u9645\u7684\u4ee3\u7801\uff0c\u56e0\u4e3a\u5b83\u5e76\u4e0d\u77e5\u9053\u5c06\u4f1a\u7528\u54ea\u4e9b\u7c7b\u578b\u6765\u5b9e\u4f8b\u5316\u8fd9\u4e2a\u6a21\u677f\u3002<\/p>\n<p><strong>\u5b9e\u4f8b\u5316\u8fc7\u7a0b<\/strong><\/p>\n<p>\u53ea\u6709\u5f53\u6a21\u677f\u5728\u5176\u4ed6\u5730\u65b9\u88ab\u5b9e\u4f8b\u5316\uff08\u5373\uff0c\u4f7f\u7528\u7279\u5b9a\u7684\u7c7b\u578b\u53c2\u6570\u6765\u521b\u5efa\u6a21\u677f\u7684\u5b9e\u4f8b\uff09\u65f6\uff0c\u7f16\u8bd1\u5668\u624d\u4f1a\u6839\u636e\u8fd9\u4e9b\u7c7b\u578b\u53c2\u6570\u6765\u751f\u6210\u5177\u4f53\u7684\u4ee3\u7801\u3002\u8fd9\u4e2a\u5b9e\u4f8b\u5316\u8fc7\u7a0b\u901a\u5e38\u53d1\u751f\u5728\u5305\u542b\u6a21\u677f\u5b9a\u4e49\u7684\u5934\u6587\u4ef6\u88ab\u5176\u4ed6\u6e90\u6587\u4ef6\u5305\u542b\uff0c\u5e76\u4e14\u8fd9\u4e9b\u6e90\u6587\u4ef6\u8bd5\u56fe\u4f7f\u7528\u7279\u5b9a\u7c7b\u578b\u7684\u6a21\u677f\u5b9e\u4f8b\u65f6\u3002<\/p>\n<p><strong>\u5206\u5272\u58f0\u660e\u548c\u5b9a\u4e49\u7684\u95ee\u9898<\/strong><\/p>\n<p>\u5982\u679c\u4f60\u5c06\u6a21\u677f\u7684\u58f0\u660e\u653e\u5728\u5934\u6587\u4ef6\u4e2d\uff0c\u800c\u5c06\u5b9a\u4e49\u653e\u5728<code>.cpp<\/code>\u6587\u4ef6\u4e2d\uff0c\u90a3\u4e48\u5f53\u4f60\u5c1d\u8bd5\u5728\u5176\u4ed6\u6e90\u6587\u4ef6\u4e2d\u4f7f\u7528\u8fd9\u4e2a\u6a21\u677f\u65f6\uff0c\u5c31\u4f1a\u9047\u5230\u95ee\u9898\u3002\u56e0\u4e3a\u5f53\u7f16\u8bd1\u5668\u7f16\u8bd1\u8fd9\u4e2a\u6e90\u6587\u4ef6\u65f6\uff0c\u5b83\u53ea\u80fd\u770b\u5230\u6a21\u677f\u7684\u58f0\u660e\uff0c\u800c\u770b\u4e0d\u5230\u5b9a\u4e49\u3002\u7531\u4e8e\u5b9a\u4e49\u4e0d\u5728\u540c\u4e00\u4e2a\u7f16\u8bd1\u5355\u5143\u4e2d\uff0c\u7f16\u8bd1\u5668\u5c31\u65e0\u6cd5\u751f\u6210\u7279\u5b9a\u7c7b\u578b\u7684\u6a21\u677f\u5b9e\u4f8b\u4ee3\u7801\u3002\u94fe\u63a5\u5668\u4e5f\u65e0\u6cd5\u94fe\u63a5\u5230\u8fd9\u4e9b\u4ee3\u7801\uff0c\u56e0\u4e3a\u5b83\u6839\u672c\u4e0d\u5b58\u5728\u3002<\/p>\n<p><strong>\u4f60\u7684\u4f8b\u5b50<\/strong><\/p>\n<p>\u5728\u4f60\u7684\u4f8b\u5b50\u4e2d\uff0c<code>template.cpp<\/code>\u4e2d\u7684\u6a21\u677f\u6210\u5458\u51fd\u6570\u5b9a\u4e49\u4e0d\u4f1a\u88ab\u7f16\u8bd1\u6210\u4e8c\u8fdb\u5236\u4ee3\u7801\uff0c\u56e0\u4e3a\u5b83\u662f\u4e00\u4e2a\u6a21\u677f\u5b9a\u4e49\uff0c\u800c\u4e0d\u662f\u4e00\u4e2a\u5177\u4f53\u7684\u51fd\u6570\u5b9a\u4e49\u3002\u53ea\u6709\u5f53<code>main.cpp<\/code>\u4e2d\u5305\u542b<code>template.h<\/code>\u5e76\u5c1d\u8bd5\u4f7f\u7528<code>TemTest&lt;int&gt;<\/code>\u65f6\uff0c\u7f16\u8bd1\u5668\u624d\u4f1a\u6839\u636e<code>int<\/code>\u7c7b\u578b\u6765\u5b9e\u4f8b\u5316<code>TemTest<\/code>\u7c7b\u53ca\u5176\u6210\u5458\u51fd\u6570<code>TestFun<\/code>\u3002<\/p>\n<p>\u5982\u679c\u4f60\u5c06<code>template.cpp<\/code>\u4e2d\u7684\u5b9a\u4e49\u79fb\u5230<code>template.h<\/code>\u4e2d\uff0c\u6216\u8005\u76f4\u63a5\u5728<code>main.cpp<\/code>\u4e2d\u5b9a\u4e49<code>TestFun<\/code>\uff0c\u90a3\u4e48\u5f53\u4f60\u7f16\u8bd1<code>main.cpp<\/code>\u65f6\uff0c\u7f16\u8bd1\u5668\u5c31\u80fd\u591f\u770b\u5230\u5b8c\u6574\u7684\u6a21\u677f\u5b9a\u4e49\uff0c\u5e76\u751f\u6210<code>TemTest&lt;int&gt;<\/code>\u7684\u5b9e\u4f8b\u4ee3\u7801\u3002<\/p>\n<h2 id=\"\u8f6c\u53d1\u6784\u9020\">\u8f6c\u53d1\u6784\u9020<\/h2>\n<p><strong>\u95ee\uff1a\u542c\u8bf4\u8fc7\u8f6c\u53d1\u6784\u9020\u4e48\uff1f<\/strong><\/p>\n<p><code>std::move<\/code>\u5c31\u662f\u5de6\u503c\u53d8\u53f3\u503c\u8282\u7701\u7a7a\u95f4\uff0c<code>std::forward<\/code>\u5c31\u662f\u5de6\u503c\u4f9d\u65e7\u4e3a\u5de6\u503c\uff0c\u53f3\u503c\u4f9d\u65e7\u4e3a\u53f3\u503c\u9632\u6b62\u9690\u5f0f\u8f6c\u6362<\/p>\n<p>std::move\u548cstd::forward\u8fd9\u4e24\u4e2aAPI\u4e3b\u8981\u670d\u52a1\u4e8e\u5de6\u503c\u5f15\u7528\u548c\u53f3\u503c\u5f15\u7528\u7684\u8f6c\u5316\u548c\u8f6c\u53d1\uff0c\u56e0\u6b64\u518d\u4e86\u89e3\u8fd9\u4e24\u4e2aAPI\u4e4b\u524d\uff0c\u9700\u8981\u5148\u5f04\u6e05\u695a\u8fd9\u51e0\u4e2a\u6982\u5ff5\u3002<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>\u5de6\u503c\uff1a\u4e00\u822c\u6307\u7684\u662f\u5728\u5185\u5b58\u4e2d\u6709\u5bf9\u5e94\u7684\u5b58\u50a8\u5355\u5143\u7684\u503c\uff0c\u6700\u5e38\u89c1\u7684\u5c31\u662f\u7a0b\u5e8f\u4e2d\u521b\u5efa\u7684\u53d8\u91cf<\/li>\n<li>\u53f3\u503c\uff1a\u548c\u5de6\u503c\u76f8\u53cd\uff0c\u4e00\u822c\u6307\u7684\u662f\u6ca1\u6709\u5bf9\u5e94\u5b58\u50a8\u5355\u5143\u7684\u503c\uff08\u5bc4\u5b58\u5668\u4e2d\u7684\u7acb\u5373\u6570\uff0c\u4e2d\u95f4\u7ed3\u679c\u7b49\uff09\uff0c\u4f8b\u5982\u4e00\u4e2a\u5e38\u91cf\uff0c\u6216\u8005\u8868\u8fbe\u5f0f\u8ba1\u7b97\u7684\u4e34\u65f6\u53d8\u91cf<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\" lang=\"cpp\">int x = 10 \nint y = 20\nint z = x + y \n\/\/x, y , z \u662f\u5de6\u503c\n\/\/10 , 20,x + y \u662f\u53f3\u503c\uff0c\u56e0\u4e3a\u5b83\u4eec\u5728\u5b8c\u6210\u8d4b\u503c\u64cd\u4f5c\u540e\u5373\u6d88\u5931\uff0c\u6ca1\u6709\u5360\u7528\u4efb\u4f55\u8d44\u6e90\n<\/code><\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>\u5de6\u503c\u5f15\u7528\uff1aC++\u4e2d\u91c7\u7528 &amp;\u5bf9\u53d8\u91cf\u8fdb\u884c\u5f15\u7528\uff0c\u8fd9\u79cd\u5e38\u89c4\u7684\u5f15\u7528\u5c31\u662f\u5de6\u503c\u5f15\u7528<\/li>\n<li>\u53f3\u503c\u5f15\u7528\uff1a\u8fd9\u4e2a\u6982\u5ff5\u5b9e\u9645\u4e0a\u4e0d\u662f\u8bf4\u5bf9\u4e0a\u8ff0\u7684\u53f3\u503c\u8fdb\u884c\u5f15\u7528\uff08\u56e0\u4e3a\u53f3\u503c\u672c\u8eab\u4e5f\u6ca1\u6709\u5bf9\u5e94\u7684\u5b58\u50a8\u5355\u5143\uff09\uff0c\u53f3\u503c\u5f15\u7528\u5b9e\u9645\u4e0a\u53ea\u662f\u4e00\u4e2a\u903b\u8f91\u4e0a\u7684\u6982\u5ff5\uff0c\u6700\u5927\u7684\u4f5c\u7528\u5c31\u662f\u8ba9\u4e00\u4e2a\u5de6\u503c\u8fbe\u5230\u7c7b\u4f3c\u53f3\u503c\u7684\u6548\u679c\uff08\u4e0b\u9762\u7a0b\u5e8f\u4e3e\u4f8b\uff09\uff0c\u8ba9\u53d8\u91cf\u4e4b\u95f4\u7684\u8f6c\u79fb\u66f4\u7b26\u5408\u201c\u8bed\u4e49\u4e0a\u7684\u8f6c\u79fb\u201d\uff0c\u4ee5\u51cf\u5c11\u8f6c\u79fb\u4e4b\u95f4\u591a\u6b21\u62f7\u8d1d\u7684\u5f00\u9500\u3002\u53f3\u503c\u5f15\u7528\u7b26\u53f7\u662f&amp;&amp;\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u5bf9\u4e8e\u4ee5\u4e0b\u7a0b\u5e8f\uff0c\u6211\u4eec\u8981\u5c06\u5b57\u7b26\u4e32\u653e\u5230vector\u4e2d\uff0c\u4e14\u6211\u4eec\u540e\u7eed\u7684\u4ee3\u7801\u4e2d\u4e0d\u518d\u7528\u5230x\uff1a<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">std::vector&lt;std::string&gt; vec;\nstd::string x = \"abcd\";\nvec.push_back(x);\nstd::cout&lt;&lt;\"x: \"&lt;&lt;x&lt;&lt;\"\\n\";\nstd::cout&lt;&lt;\"vector: \"&lt;&lt; vec[0]&lt;&lt;\"\\n\";\n\n\/\/-------------output------------------\n\/\/ x: abcd\n\/\/ vector: abcd\n<\/code><\/pre>\n<p>\u8be5\u7a0b\u5e8f\u5728\u771f\u6b63\u6267\u884c\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5b9e\u9645\u4e0a\u662f\u590d\u5236\u4e86\u4e00\u4efd\u5b57\u7b26\u4e32x\uff0c\u5c06\u5176\u653e\u5728vector\u4e2d\uff0c\u8fd9\u5176\u4e2d\u591a\u4e86\u4e00\u4e2a\u62f7\u8d1d\u7684\u5f00\u9500\u548c\u5185\u5b58\u4e0a\u7684\u5f00\u9500\u3002\u4f46\u5982\u679cx\u4ee5\u53ca\u6ca1\u6709\u4f5c\u7528\u4e86\uff0c\u6211\u4eec\u5e0c\u671b\u505a\u5230\u7684\u662f <strong>\u771f\u6b63<\/strong>\u7684\u8f6c\u79fb\uff0c\u5373x\u6307\u5411\u7684\u5b57\u7b26\u4e32\u79fb\u52a8\u5230vector\u4e2d\uff0c\u4e0d\u9700\u8981\u989d\u5916\u7684\u5185\u5b58\u5f00\u9500\u548c\u62f7\u8d1d\u5f00\u9500\u3002\u56e0\u6b64\u6211\u4eec\u5e0c\u671b\u8ba9\u53d8\u91cf x\u4f20\u5165\u5230push_back <strong>\u8868\u73b0\u7684\u50cf\u4e00\u4e2a\u53f3\u503c<\/strong> \uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u4f53\u73b0\u53f3\u503c\u5f15\u7528\u7684\u4f5c\u7528\uff0c\u53ea\u9700\u8981\u5c06<code>x<\/code>\u7684\u53f3\u503c\u5f15\u7528\u4f20\u5165\u5c31\u53ef\u4ee5\u3002<\/p>\n<p><strong>std::move<\/strong><\/p>\n<p>\u524d\u9762\u63d0\u5230\u4e86\u53f3\u503c\u5f15\u7528\u7684\u4e3b\u8981\u4f5c\u7528\u662f\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u62f7\u8d1d\u5f00\u9500\u548c\u5185\u5b58\u5f00\u9500\u3002\u800cstd::move\u7684\u4f5c\u7528\u5c31\u662f\u8fdb\u884c\u65e0\u6761\u4ef6\u8f6c\u5316\uff0c\u4efb\u4f55\u7684\u5de6\u503c\/\u53f3\u503c\u901a\u8fc7std::move\u90fd\u8f6c\u5316\u4e3a\u53f3\u503c\u5f15\u7528\u3002\u5c06\u4e0a\u9762\u7684\u7a0b\u5e8f\u6539\u5199\u6210\u53f3\u503c\u5f15\u7528\u7684\u65b9\u5f0f<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">std::vector&lt;std::string&gt; vec;\nstd::string x = \"abcd\";\nvec.push_back(std::move(x));\nstd::cout&lt;&lt;\"x: \"&lt;&lt;x&lt;&lt;\"\\n\";\nstd::cout&lt;&lt;\"vector: \"&lt;&lt; vec[0]&lt;&lt;\"\\n\";\n\/\/-------------output------------------\n\/\/ x: \n\/\/ vector: abcd\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5b8c\u6210<code>push_back<\/code>\u540e<code>x<\/code>\u662f\u7a7a\u7684\u3002<\/p>\n<p><strong>std::forward<\/strong><\/p>\n<p>std::forward\u7684\u4f5c\u7528\u662f\u5b8c\u7f8e\u8f6c\u53d1\uff0c\u5982\u679c\u4f20\u9012\u7684\u662f\u5de6\u503c\u8f6c\u53d1\u7684\u5c31\u662f\u5de6\u503c\u5f15\u7528\uff0c\u4f20\u9012\u7684\u662f\u53f3\u503c\u8f6c\u53d1\u7684\u5c31\u662f\u53f3\u503c\u5f15\u7528\u3002<\/p>\n<p>\u5728\u5177\u4f53\u4ecb\u7ecdstd::forward\u4e4b\u524d\uff0c\u9700\u8981\u5148\u4e86\u89e3C++\u7684\u5f15\u7528\u6298\u53e0\u89c4\u5219\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u503c\u5f15\u7528\u7684\u5f15\u7528\u6700\u7ec8\u90fd\u4f1a\u88ab\u6298\u53e0\u6210\u5de6\u503c\u5f15\u7528\u6216\u8005\u53f3\u503c\u5f15\u7528\u3002<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>T&amp; &amp; -&gt; T&amp; \uff08\u5bf9\u5de6\u503c\u5f15\u7528\u7684\u5de6\u503c\u5f15\u7528\u662f\u5de6\u503c\u5f15\u7528\uff09<\/li>\n<li>T&amp; &amp;&amp; -&gt; T&amp; \uff08\u5bf9\u5de6\u503c\u5f15\u7528\u7684\u53f3\u503c\u5f15\u7528\u662f\u5de6\u503c\u5f15\u7528\uff09<\/li>\n<li>T&amp;&amp; &amp; -&gt;T&amp; \uff08\u5bf9\u53f3\u503c\u5f15\u7528\u7684\u5de6\u503c\u5f15\u7528\u662f\u5de6\u503c\u5f15\u7528\uff09<\/li>\n<li><strong>T&amp;&amp; &amp;&amp; -&gt;T&amp;&amp; \uff08\u5bf9\u53f3\u503c\u5f15\u7528\u7684\u53f3\u503c\u5f15\u7528\u662f\u53f3\u503c\u5f15\u7528\uff09<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u53ea\u6709\u5bf9\u4e8e\u53f3\u503c\u5f15\u7528\u7684\u53f3\u503c\u5f15\u7528\u6298\u53e0\u5b8c\u8fd8\u662f\u53f3\u503c\u5f15\u7528\uff0c\u5176\u4ed6\u90fd\u4f1a\u88ab\u6298\u53e0\u6210\u5de6\u503c\u5f15\u7528\uff0c\u6839\u636e\u6298\u53e0\u89c4\u5219\uff0c\u53ef\u4ee5\u6784\u9020\u51fa\u4e00\u4e2a\u901a\u7528\u5f15\u7528\u3002<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">#include&lt;iostream&gt;\ntemplate &lt;typename T&gt;\nvoid foo(T&amp;&amp; param){\n   if(std::is_rvalue_reference&lt;decltype(param)&gt;::value)\n        std::cout&lt;&lt;\"rvalue reference\\n\";\n    else std::cout&lt;&lt;\"lvalue reference\\n\";\n}\nint main(){\n    int a = 0;\n    foo(a);  \n    foo(std::move(a)); \n    return 0;\n}\n\n\/\/------------output----------\n\/\/ lvalue reference\n\/\/ rvalue reference\n<\/code><\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><code>foo(a)<\/code> \uff0cT\u5c31\u662fint &amp;\uff0c\u5219param\u7684\u7c7b\u578b\u4e3aT&amp;&amp;-&gt;int &amp; &amp;&amp;-&gt;int &amp;<\/li>\n<li><code>foo(std::move(a))<\/code>\uff0cstd::move\u8f6c\u6210\u53f3\u503c\u5f15\u7528,\u90a3\u4e48T\u5c31\u662fint&amp;&amp;\uff0c\u5219param\u7684\u7c7b\u578b\u4e3aT &amp;&amp;-&gt;int &amp;&amp; &amp;&amp;-&gt;int &amp;&amp;<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u524d\u9762\u63d0\u5230\u7684std::move\u53ef\u4ee5\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u62f7\u8d1d\u5f00\u9500\uff0c\u53ef\u4ee5\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6548\u7387\uff0c\u4f46\u662fstd::forward\u7684\u4f5c\u7528\u662f\u8f6c\u53d1\uff0c\u5de6\u503c\u5f15\u7528\u8f6c\u53d1\u6210\u5de6\u503c\u5f15\u7528\uff0c\u53f3\u503c\u5f15\u7528\u8fd8\u662f\u53f3\u503c\u5f15\u7528\uff0c\u521a\u5f00\u59cb\u4e00\u76f4\u60f3\u4e0d\u901a\u8fd9\u4e2aAPI\u7684\u610f\u4e49\u5230\u5e95\u662f\u4ec0\u4e48\uff1f<\/p>\n<p>\u539f\u6765\u662f\u5728\u7a0b\u5e8f\u7684\u6267\u884c\u8fc7\u7a0b\u4e2d\uff0c\u5bf9\u4e8e\u5f15\u7528\u7684\u4f20\u9012\u5b9e\u9645\u4e0a\u4f1a\u6709\u989d\u5916\u7684\u9690\u5f0f\u7684\u8f6c\u5316\uff0c\u4e00\u4e2a\u53f3\u503c\u5f15\u7528\u53c2\u6570\u7ecf\u8fc7\u51fd\u6570\u7684\u8c03\u7528\u8f6c\u53d1\u53ef\u80fd\u4f1a\u8f6c\u5316\u6210\u5de6\u503c\u5f15\u7528\uff0c\u4f46\u8fd9\u5c31\u4e0d\u662f\u6211\u4eec\u5e0c\u671b\u770b\u5230\u7684\u7ed3\u679c\u3002<\/p>\n<p>\u5728\u4e0a\u9762\u7684\u7a0b\u5e8f\u4e0a\u8fdb\u884c\u4fee\u6539<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">#include &lt;iostream&gt;\n#include &lt;vector&gt;\n#include &lt;string&gt;\n\nclass A {\n  public:\n    A(){}\n    A(size_t size): size(size), array((int*) malloc(size)) {\n        std::cout \n          &lt;&lt; \"create Array\uff0cmemory at: \"  \n          &lt;&lt; array &lt;&lt; std::endl;\n        \n    }\n    ~A() {\n        free(array);\n    }\n    A(A &amp;&amp;a) : array(a.array), size(a.size) {\n        a.array = nullptr;\n        std::cout \n          &lt;&lt; \"Array moved, memory at: \" \n          &lt;&lt; array \n          &lt;&lt; std::endl;\n    }\n    A(A &amp;a) : size(a.size) {\n        array = (int*) malloc(a.size);\n        for(int i = 0;i &lt; a.size;i++)\n            array[i] = a.array[i];\n        std::cout \n          &lt;&lt; \"Array copied, memory at: \" \n          &lt;&lt; array &lt;&lt; std::endl;\n    }\n    size_t size;\n    int *array;\n};\ntemplate&lt;typename T&gt;\nvoid warp(T&amp;&amp; param) {\n    if(std::is_rvalue_reference&lt;decltype(param)&gt;::value){\n        std::cout&lt;&lt;\"param is rvalue reference\\n\";\n    }\n    else std::cout&lt;&lt;\"param is lvalue reference\\n\";\n    A y = A(param);  \/\/\u8fd9\u91ccparam\u88ab\u5f53\u4f5c\u5de6\u503c\u5904\u7406\n    A z = A(std::forward&lt;T&gt;(param));\n}\nint main(){\n    A a = A(100);\n    warp(std::move(a));\n    return 0;   \n}\n\n\/\/----------------output----------------\n\/\/ create Array\uff0cmemory at: 0x600002e60000 \/\/main\u51fd\u6570\u4e2d\uff0cA a = A(100);\u8c03\u7528\u6784\u9020\u51fd\u6570\n\/\/ param is rvalue reference \/\/\u4f7f\u7528\u4e86std::move\uff0c\u6839\u636e\u5f15\u7528\u6298\u53e0\u89c4\u5219\uff0cparam\u662f\u4e00\u4e2a\u53f3\u503c\u5f15\u7528\n\/\/ Array copied, memory at: 0x600002e60070 \/\/ A y = A(param); \u53ef\u4ee5\u770b\u5230\u8c03\u7528\u7684\u662f\u62f7\u8d1d\u7684\u6784\u9020\u51fd\u6570\n\/\/ Array moved, memory at: 0x600002e60000\u3002\/\/ A z = A(std::forward&lt;T&gt;(param)); \u8c03\u7528\u4e86\u79fb\u52a8\u6784\u9020\u51fd\u6570\n<\/code><\/pre>\n<p>\u4ece\u7a0b\u5e8f\u7684\u8f93\u51fa\u5c31\u53ef\u4ee5\u770b\u5230\uff0c\u5f53\u4e00\u4e2a\u53f3\u503c\u5f15\u7528\u518d\u8fdb\u884c\u8f6c\u53d1\u7684\u65f6\u5019\uff0c\u6ca1\u4f7f\u7528std::forward\u8fdb\u884c\u4e8c\u6b21\u8f6c\u53d1\u7684\u65f6\u5019\uff0c\u5b9e\u9645\u4e0a\u662f\u4f1a\u88ab\u9690\u5f0f\u7684\u8f6c\u6362\uff0c\u8f6c\u53d1\u6210\u4e00\u4e2a\u5de6\u503c\u5f15\u7528\uff0c\u4ece\u800c\u8c03\u7528\u4e0d\u7b26\u5408\u671f\u5f85\u7684\u6784\u9020\u51fd\u6570\uff0c\u5e26\u6765\u989d\u5916\u7684\u5f00\u9500\uff0c\u6240\u4ee5std::forward\u7684\u4e00\u4e2a\u91cd\u8981\u4f5c\u7528\u5c31\u662f<strong>\u5b8c\u7f8e\u8f6c\u53d1\uff0c\u786e\u4fdd<\/strong>\u8f6c\u53d1\u8fc7\u7a0b\u4e2d\u5f15\u7528\u7684\u7c7b\u578b\u4e0d\u53d1\u751f\u4efb\u4f55\u6539\u53d8\uff0c<strong>\u5de6\u503c\u5f15\u7528\u8f6c\u53d1\u540e\u4e00\u5b9a\u8fd8\u662f\u5de6\u503c\u5f15\u7528\uff0c\u53f3\u503c\u5f15\u7528\u8f6c\u53d1\u540e\u4e00\u5b9a\u8fd8\u662f\u53f3\u503c\u5f15\u7528<\/strong>\uff01<\/p>\n<h2 id=\"\u51fd\u6570\u8c03\u7528\">\u51fd\u6570\u8c03\u75281<\/h2>\n<p><strong>\u95ee\uff1a\u63cf\u8ff0\u4e00\u4e0b\u51fd\u6570\u8c03\u7528\u8fc7\u7a0b\u4e2d\u6808\u7684\u53d8\u5316<\/strong><\/p>\n<p>\u6808\u5e27(stack frame)\uff1a\u673a\u5668\u7528\u6808\u6765\u4f20\u9012\u8fc7\u7a0b\u53c2\u6570\uff0c\u5b58\u50a8\u8fd4\u56de\u4fe1\u606f\uff0c\u4fdd\u5b58\u5bc4\u5b58\u5668\u7528\u4e8e\u4ee5\u540e\u6062\u590d\uff0c\u4ee5\u53ca\u672c\u5730\u5b58\u50a8\u3002\u4e3a\u5355\u4e2a\u8fc7\u7a0b(\u51fd\u6570\u8c03\u7528)\u5206\u914d\u7684\u90a3\u90e8\u5206\u6808\u79f0\u4e3a\u6808\u5e27\u3002\u6808\u5e27\u5176\u5b9e\u662f\u4e24\u4e2a\u6307\u9488\u5bc4\u5b58\u5668\uff0c\u5bc4\u5b58\u5668ebp\u4e3a\u5e27\u6307\u9488\uff08\u6307\u5411\u8be5\u6808\u5e27\u7684\u6700\u5e95\u90e8\uff09\uff0c\u800c\u5bc4\u5b58\u5668esp\u4e3a\u6808\u6307\u9488\uff08\u6307\u5411\u8be5\u6808\u5e27\u7684\u6700\u9876\u90e8\uff09\u3002<\/p>\n<p>\u7136\u540e\u6211\u4eec\u518d\u7b80\u5355\u63cf\u8ff0\u4e00\u4e0b\u51fd\u6570\u8c03\u7528\u7684\u673a\u5236\uff0c\u6bcf\u4e2a\u51fd\u6570\u6709\u81ea\u5df1\u7684\u51fd\u6570\u8c03\u7528\u5730\u5740\uff0c\u91cc\u9762\u4f1a\u6709\u5404\u79cd\u6307\u4ee4\u64cd\u4f5c\uff08\u8fd9\u7aef\u5185\u5b58\u4f4d\u4e8e\u201c\u4ee3\u7801\u6bb5\u201d\u90e8\u5206\uff09\uff0c\u51fd\u6570\u7684\u53c2\u6570\u4e0e\u5c40\u90e8\u53d8\u91cf\u4f1a\u88ab\u521b\u5efa\u5e76\u538b\u7f29\u5230\u201c\u6808\u201d\u7684\u91cc\u9762\uff0c\u5e76\u7531\u4e24\u4e2a\u6307\u9488\u5206\u522b\u6307\u5411\u5f53\u524d\u5e27\u6808\u9876\u548c\u5e27\u6808\u5c3e\u3002\u5f53\u8fdb\u5165\u53e6\u4e00\u4e2a\u5b50\u51fd\u6570\u65f6\u5019\uff0c\u5f53\u524d\u51fd\u6570\u7684\u76f8\u5173\u6570\u636e\u4f1a\u88ab\u4fdd\u5b58\u5230\u6808\u91cc\u9762\uff0c\u5e76\u538b\u5165\u5f53\u524d\u7684\u8fd4\u56de\u5730\u5740\u3002\u5b50\u51fd\u6570\u6267\u884c\u65f6\u4e5f\u4f1a\u6709\u81ea\u5df1\u7684\u201c\u6808\u5e27\u201d\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\u4f1a\u8c03\u7528CPU\u7684\u5bc4\u5b58\u673a\u8fdb\u884c\u8ba1\u7b97\uff0c\u8ba1\u7b97\u540e\u518d\u5f39\u51fa\u201c\u6808\u5e27\u201d\u76f8\u5173\u6570\u636e\uff0c\u901a\u8fc7\u201c\u6808\u201d\u91cc\u9762\u4e4b\u524d\u4fdd\u5b58\u7684\u8fd4\u56de\u5730\u5740\u518d\u56de\u5230\u539f\u6765\u7684\u4f4d\u7f6e\u6267\u884c\u524d\u9762\u7684\u51fd\u6570\u3002<\/p>\n<p>\u9996\u5148\uff0c\u4ec0\u4e48\u662f\u6808\u5e27\uff1f\u5f15\u7528\u767e\u5ea6\u767e\u79d1\uff1aC\u8bed\u8a00\u4e2d\uff0c\u6bcf\u4e2a\u6808\u5e27\u5bf9\u5e94\u7740\u4e00\u4e2a\u672a\u8fd0\u884c\u5b8c\u7684\u51fd\u6570\u3002\u6808\u5e27\u4e2d\u4fdd\u5b58\u4e86\u8be5\u51fd\u6570\u7684\u8fd4\u56de\u5730\u5740\u548c\u5c40\u90e8\u53d8\u91cf\u3002\u4ece\u8fd9\u53e5\u8bdd\u4e2d\uff0c\u53ef\u4ee5\u63d0\u70bc\u4ee5\u4e0b\u51e0\u70b9\u4fe1\u606f\uff1a<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>\u6808\u5e27\u662f\u4e00\u5757\u56e0\u51fd\u6570\u8fd0\u884c\u800c\u4e34\u65f6\u5f00\u8f9f\u7684\u7a7a\u95f4\u3002<\/li>\n<li>\u6bcf\u8c03\u7528\u4e00\u6b21\u51fd\u6570\u4fbf\u4f1a\u521b\u5efa\u4e00\u4e2a\u72ec\u7acb\u6808\u5e27\u3002<\/li>\n<li>\u6808\u5e27\u4e2d\u5b58\u653e\u7684\u662f\u51fd\u6570\u4e2d\u7684\u5fc5\u8981\u4fe1\u606f\uff0c\u5982\u5c40\u90e8\u53d8\u91cf\u3001\u51fd\u6570\u4f20\u53c2\u3001\u8fd4\u56de\u503c\u7b49\u3002<\/li>\n<li>\u5f53\u51fd\u6570\u8fd0\u884c\u5b8c\u6bd5\u6808\u5e27\u5c06\u4f1a\u9500\u6bc1\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u5e38\u7528\u5bc4\u5b58\u5668\u53ca\u7b80\u5355\u6c47\u7f16\u6307\u4ee4<\/strong><\/p>\n<figure class=\"table-figure\">\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u5bc4\u5b58\u5668<\/th>\n<th style=\"text-align: center;\">\u7528\u9014<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">EAX<\/td>\n<td style=\"text-align: center;\">\u7d2f\u52a0\u5bc4\u5b58\u5668\uff1a\u7528\u4e8e\u4e58\u9664\u6cd5\u3001\u51fd\u6570\u8fd4\u56de\u503c<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">EBX<\/td>\n<td style=\"text-align: center;\">\u7528\u4e8e\u5b58\u653e\u5185\u5b58\u6570\u636e\u6307\u9488<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">ECX<\/td>\n<td style=\"text-align: center;\">\u8ba1\u6570\u5668<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">EDX<\/td>\n<td style=\"text-align: center;\">\u7528\u4e8e\u4e58\u9664\u6cd5\u3001IO\u6307\u9488<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">ESI<\/td>\n<td style=\"text-align: center;\">\u6e90\u7d22\u5f15\u5bc4\u5b58\u5668\uff0c\u5b58\u653e\u6e90\u5b57\u7b26\u4e32\u6307\u9488<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">EDI<\/td>\n<td style=\"text-align: center;\">\u76ee\u6807\u7d22\u5f15\u5bc4\u5b58\u5668\uff0c\u5b58\u653e\u76ee\u6807\u5b57\u7b26\u4e32\u6307\u9488EAX<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">ESP<\/td>\n<td style=\"text-align: center;\">\u5b58\u653e\u6808\u9876\u6307\u9488<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">EBP<\/td>\n<td style=\"text-align: center;\">\u5b58\u653e\u6808\u5e95\u6307\u9488<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<figure class=\"table-figure\">\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u6c47\u7f16\u6307\u4ee4<\/th>\n<th style=\"text-align: center;\">\u7528\u9014<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">mov<\/td>\n<td style=\"text-align: center;\">mov A,B \u5c06\u6570\u636eB\u79fb\u52a8\u5230A<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">push<\/td>\n<td style=\"text-align: center;\">\u538b\u6808<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">pop<\/td>\n<td style=\"text-align: center;\">\u51fa\u6808<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">call<\/td>\n<td style=\"text-align: center;\">\u51fd\u6570\u8c03\u7528<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">add<\/td>\n<td style=\"text-align: center;\">\u52a0\u6cd5<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">sub<\/td>\n<td style=\"text-align: center;\">\u51cf\u6cd5<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">rep<\/td>\n<td style=\"text-align: center;\">\u91cd\u590d<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">lea<\/td>\n<td style=\"text-align: center;\">\u52a0\u8f7d\u6709\u6548\u5730\u5740<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h3 id=\"main\u51fd\u6570\u6808\u5e27\u521b\u5efa\u52a8\u6001\u6f14\u793a\"><strong>main\u51fd\u6570\u6808\u5e27\u521b\u5efa\u52a8\u6001\u6f14\u793a<\/strong> <div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040104.gif'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040104.gif\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" \/><\/div><\/h3>\n<pre><code>008B1410  push        ebp  \n008B1411  mov         ebp,esp  \n008B1413  sub         esp,0E4h  \n008B1419  push        ebx  \n008B141A  push        esi  \n008B141B  push        edi  \n008B141C  lea         edi,[ebp-0E4h]  \n008B1422  mov         ecx,39h  \n008B1427  mov         eax,0CCCCCCCCh  \n008B142C  rep stos    dword ptr es:[edi] \/\/dword \u4e3a 4\u4e2a\u5b57\u8282\n<\/code><\/pre>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040105.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040105.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" \/><\/div><\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>\u5728__tmainCRTStartup()\u51fd\u6570\u9876\u90e8\u538b\u5165ebp\uff0c\u5982\u56fe\u6240\u793aesp\u6307\u5411ebp\uff0cebp\u6210\u529f\u538b\u5165\u6808\u4e2d\u3002<\/li>\n<li>esp\u503c\u4f20\u9012\u7ed9ebp\u3002<\/li>\n<li>esp\u51cf\u53bb0E4h\uff1a\u7531\u4e8e\u6808\u5148\u4f7f\u7528\u9ad8\u5730\u5740\u540e\u4f7f\u7528\u4f4e\u5730\u5740\uff0c\u51cf\u53bb\u4e00\u4e2a\u503c\u610f\u5473\u7740esp\u6307\u9488\u5411\u4f4e\u5730\u5740\u79fb\u52a8\u4e860E4h\u4e2a\u5730\u5740\uff0c\u6b64\u5904\u4fbf\u5f00\u8f9f\u4e86main\u51fd\u6570\u7684\u6808\u5e27\u3002<\/li>\n<li>\u538b\u5165ebx\uff0cesp\u6307\u5411ebx\u9876\u90e8\u3002<\/li>\n<li>\u538b\u5165esi\uff0cesp\u6307\u5411esi\u9876\u90e8\u3002<\/li>\n<li>\u538b\u5165edi\uff0cesp\u6307\u5411edi\u9876\u90e8\u3002<\/li>\n<li>\u5c06edi\u5411\u4e0b39h\u4e2a\u7a7a\u95f4\u5168\u90e8\u6539\u4e3a0xCCCCCCCC\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3 id=\"\u5c40\u90e8\u53d8\u91cf\u521b\u5efa\">\u5c40\u90e8\u53d8\u91cf\u521b\u5efa<\/h3>\n<pre><code>int a = 10;\n00AA142E  mov         dword ptr [ebp-8],0Ah  \n\tint b = 20;\n00AA1435  mov         dword ptr [ebp-14h],14h  \n\tint ret = 0;\n00AA143C  mov         dword ptr [ebp-20h],0  \n<\/code><\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>\u5c06\u5341\u516d\u8fdb\u5236\u6574\u6570:0Ah\uff08DEC 10\uff09\u653e\u5165ebp \u5411\u4f4e\u5730\u5740\u79fb\u52a88\u4e2a\u5b57\u8282\u3002<\/li>\n<li>\u5c06\u5341\u516d\u8fdb\u5236\u6574\u6570:14h\uff08DEC 20\uff09\u653e\u5165ebp \u5411\u4f4e\u5730\u5740\u79fb\u52a820\u4e2a\u5b57\u8282\u3002<\/li>\n<li>\u5c06\u5341\u516d\u8fdb\u5236\u6574\u6570:0\uff08DEC 0\uff09\u653e\u5165ebp \u5411\u4f4e\u5730\u5740\u79fb\u52a832\u4e2a\u5b57\u8282\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040106.gif'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040106.gif\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" \/><\/div><\/p>\n<h3 id=\"\u51fd\u6570\u4f20\u53c2\u548c\u8c03\u7528\">\u51fd\u6570\u4f20\u53c2\u548c\u8c03\u7528<\/h3>\n<pre><code>ret = Add(a, b);\n00AA1443  mov         eax,dword ptr [ebp-14h]  \n00AA1446  push        eax  \n00AA1447  mov         ecx,dword ptr [ebp-8]  \n00AA144A  push        ecx  \n00AA144B  call        00AA10E1  \n00AA1450  add         esp,8  \n00AA1453  mov         dword ptr [ebp-20h],eax  \n<\/code><\/pre>\n<p>\u4ece\u4ee5\u4e0a\u6c47\u7f16\u4ee3\u7801\u53ef\u77e5\u51fd\u6570\u662f\u5148\u4f20\u53c2\u540e\u8c03\u7528\uff0c\u51fd\u6570\u4f20\u53c2\u987a\u5e8f\u662f\u4ece\u53f3\u5f80\u5de6\u3002<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>ebp &#8211; 14h \u7684\u5730\u5740\u4f20\u7ed9eax\uff0c\u5373eax\u4e2d\u5b9e\u9645\u5b58\u653e\u4e8620\u3002<\/li>\n<li>eax \u538b\u6808\u3002<\/li>\n<li>ebp &#8211; 8 \u7684\u5730\u5740\u4f20\u7ed9ecx\uff0c\u5373ecx\u4e2d\u5b9e\u9645\u5b58\u653e\u4e8610\u3002<\/li>\n<li>ecx \u538b\u6808\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040107.gif'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040107.gif\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" \/><\/div><\/p>\n<p>\u5728\u51fd\u6570\u6808\u5e27\u3001\u5c40\u90e8\u53d8\u91cf\u521b\u5efa\u5b8c\u6bd5\u540e\uff0c\u8fdb\u884cAdd()\u51fd\u6570\u8fd0\u7b97\u8fc7\u7a0b\uff1a<\/p>\n<pre><code>c = a + b;\n00AA13E5  mov         eax,dword ptr [ebp+8]  \n00AA13E8  add         eax,dword ptr [ebp+0Ch]  \n00AA13EB  mov         dword ptr [ebp-8],eax  \n<\/code><\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>\u5c06\uff08ebp + 8\uff09\u7684\u503c\u4f20\u9012\u7ed9eax\uff0c\u6b64\u65f6\u7684ebp\u5b58\u653eAdd\u51fd\u6570\u7684\u6808\u5e95\u6307\u9488\uff0c\uff08ebp + 8\uff09 \u7684\u4f4d\u7f6e\u5373\u51fd\u6570\u4f20\u53c2\u65f6\u521b\u5efa\u7684ecx\u7684\u5730\u5740\uff0c\u5176\u5185\u90e8\u5b58\u653e\u7684\u6b63\u662f10\u3002<\/li>\n<li>eax\u5bc4\u5b58\u5668\u4e2d\u6267\u884c\u6c42\u548c\u6307\u4ee4\uff0c\u52a0\u4e0a\uff08ebp + 0ch) \u4e2d\u7684\u503c\uff0c\u540c\u7406\u53ef\u4ee5\u5f97\u77e5\uff08ebp + 0ch\uff09\u4e2d\u7684\u503c\u662f20\u3002<\/li>\n<li>\u5c06eax\u7684\u7ecf\u8fc7\u6c42\u548c\u7684\u7ed3\u679c\uff0c\u4f20\u9012\u5230\uff08ebp &#8211; 8\uff09\u7684\u4f4d\u7f6e \u3002<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040108.gif'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040108.gif\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" \/><\/div><\/p>\n<h3 id=\"\u51fd\u6570\u8fd4\u56de\">\u51fd\u6570\u8fd4\u56de<\/h3>\n<pre><code>return c;\n00AA13EE  mov         eax,dword ptr [ebp-8]  \n<\/code><\/pre>\n<p>\u5c06\u8fd4\u56de\u503c\u4f20\u9012\u81f3\u5bc4\u5b58\u5668eax\u4e2d\uff0c\u56e0\u6b64\u5728\u51fd\u6570\u8c03\u7528\u7ed3\u675f\u51fd\u6570\u6808\u5e27\u88ab\u9500\u6bc1\u65f6\uff0c\u8fd4\u56de\u503c\u5e76\u4e0d\u4f1a\u9500\u6bc1\u3002\u5728\u51fd\u6570\u62ff\u5230\u8fd4\u56de\u503c\u540e\uff0c\u5f00\u59cb\u51fa\u6808\uff1a<\/p>\n<pre><code>00AA13F1  pop         edi  \n00AA13F2  pop         esi  \n00AA13F3  pop         ebx  \n00AA13F4  mov         esp,ebp  \n00AA13F6  pop         ebp  \n00AA13F7  ret  \n<\/code><\/pre>\n<p>\u4ece\u4f4e\u4f4d\u7f6e\u5230\u9ad8\u4f4d\u7f6e\u4f9d\u6b21\u5f39\u51faedi\uff0cesi\uff0cebx\uff0c\u968f\u540e\u5c06ebp\u8d4b\u7ed9esp\u5e76\u5f39\u51faebp\uff0c\u6700\u540e\u6267\u884cret\u6307\u4ee4\u8fd4\u56de\u5230\u8c03\u7528Add\u51fd\u6570\u7684call\u6307\u4ee4\u7684\u4e0b\u4e00\u5730\u5740\uff0c\u5728\u6267\u884cret\u6307\u4ee4\u65f6\u5b9e\u9645\u5df2\u5f39\u51faAfter call\uff0c\u4ee5\u6267\u884c\u6307\u4ee4 add esp,8\uff0c\u6b64\u65f6esp\u5411\u9ad8\u5730\u5740\u79fb\u52a88\u5b57\u8282\uff0cesp\uff0cebp\u91cd\u65b0\u7ef4\u62a4main\u51fd\u6570\uff0ceax\u4e2d\u5b58\u653e\u7684\u8fd4\u56de\u503c\u5c06\u88ab\u4f20\u9012\u7ed9\u5730\u5740\uff08ebp &#8211; 20h\uff09\u5373ret\u7684\u5730\u5740\u3002\u81f3\u6b64\uff0cAdd\u51fd\u6570\u8fd4\u56de\u5b8c\u6bd5\u3002main\u51fd\u6570\u6808\u5e27\u9500\u6bc1\u8fc7\u7a0b\u4e0e\u524d\u8ff0\u8fc7\u7a0b\u7c7b\u4f3c\u3002<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040109.gif'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/pic.vanforever.com.cn\/C%2B%2B\/20240401\/2024040109.gif\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" \/><\/div><\/p>\n<h2 id=\"\u51fd\u6570\u8c03\u7528-2\">\u51fd\u6570\u8c03\u75282<\/h2>\n<p><strong>\u95ee\uff1a<strong>cdecl\/<\/strong>stdcall\u662f\u4ec0\u4e48\u610f\u601d<\/strong><\/p>\n<p><code>__cdecl<\/code> \u548c <code>__stdcall<\/code> \u662f\u4e24\u79cd\u5e38\u89c1\u7684\u8c03\u7528\u7ea6\u5b9a\uff08Calling Conventions\uff09\u5728 x86 \u67b6\u6784\u7684 Windows \u5e73\u53f0\u4e0a\u3002\u8fd9\u4e9b\u8c03\u7528\u7ea6\u5b9a\u5b9a\u4e49\u4e86\u51fd\u6570\u5982\u4f55\u63a5\u6536\u53c2\u6570\u3001\u8fd4\u56de\u7ed3\u679c\u4ee5\u53ca\u5982\u4f55\u6e05\u7406\u6808\u3002\u4e0b\u9762\u662f\u5b83\u4eec\u4e4b\u95f4\u7684\u4e3b\u8981\u533a\u522b\uff1a<\/p>\n<h3 id=\"cdecl\">__cdecl<\/h3>\n<p><code>__cdecl<\/code>\uff08C declaration\uff09\u662f C \u8bed\u8a00\u9ed8\u8ba4\u7684\u8c03\u7528\u7ea6\u5b9a\u3002\u5b83\u7684\u7279\u70b9\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>\u53c2\u6570\u4ece\u53f3\u5230\u5de6\u5165\u6808\u3002<\/li>\n<li>\u8c03\u7528\u8005\u8d1f\u8d23\u6e05\u7406\u6808\uff08\u5373\u5c06\u53c2\u6570\u4ece\u6808\u4e2d\u5f39\u51fa\uff09\u3002<\/li>\n<li>\u8fd4\u56de\u503c\u901a\u5e38\u653e\u5728 EAX \u5bc4\u5b58\u5668\u4e2d\uff08\u5bf9\u4e8e\u6574\u6570\uff09\u6216\u8005\u901a\u8fc7\u6307\u9488\u53c2\u6570\u8fd4\u56de\uff08\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u7ed3\u6784\uff09\u3002<\/li>\n<li>\u53ef\u4ee5\u652f\u6301\u53ef\u53d8\u6570\u91cf\u7684\u53c2\u6570\uff08\u5982 <code>printf<\/code> \u51fd\u6570\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u7531\u4e8e\u8c03\u7528\u8005\u8d1f\u8d23\u6e05\u7406\u6808\uff0c<code>__cdecl<\/code> \u5728\u51fd\u6570\u8fd4\u56de\u540e\uff0c\u6808\u6307\u9488\u4f1a\u6307\u5411\u8c03\u7528\u8005\u4e4b\u524d\u7684\u72b6\u6001\uff0c\u56e0\u6b64\u5b83\u63d0\u4f9b\u4e86\u5f88\u5927\u7684\u7075\u6d3b\u6027\uff0c\u4f46\u4e5f\u53ef\u80fd\u5bfc\u81f4\u6808\u7684\u4e0d\u5e73\u8861\uff0c\u5982\u679c\u51fd\u6570\u548c\u8c03\u7528\u8005\u4e4b\u95f4\u7684\u7ea6\u5b9a\u4e0d\u4e00\u81f4\u3002<\/p>\n<h3 id=\"stdcall\">__stdcall<\/h3>\n<p><code>__stdcall<\/code>\uff08Standard Call\uff09\u662f Windows API \u51fd\u6570\u7ecf\u5e38\u4f7f\u7528\u7684\u8c03\u7528\u7ea6\u5b9a\u3002\u5b83\u7684\u7279\u70b9\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>\u53c2\u6570\u4ece\u53f3\u5230\u5de6\u5165\u6808\u3002<\/li>\n<li>\u88ab\u8c03\u7528\u8005\uff08\u5373\u51fd\u6570\u672c\u8eab\uff09\u8d1f\u8d23\u6e05\u7406\u6808\u3002<\/li>\n<li>\u8fd4\u56de\u503c\u901a\u5e38\u653e\u5728 EAX \u5bc4\u5b58\u5668\u4e2d\uff08\u5bf9\u4e8e\u6574\u6570\uff09\u3002<\/li>\n<li>\u4e0d\u652f\u6301\u53ef\u53d8\u6570\u91cf\u7684\u53c2\u6570\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u7531\u4e8e\u88ab\u8c03\u7528\u8005\u8d1f\u8d23\u6e05\u7406\u6808\uff0c<code>__stdcall<\/code> \u4fdd\u8bc1\u4e86\u6808\u7684\u5e73\u8861\uff0c\u5373\u4f7f\u5728\u53d1\u751f\u5f02\u5e38\u7684\u60c5\u51b5\u4e0b\u3002\u8fd9\u4f7f\u5f97\u5b83\u975e\u5e38\u9002\u5408\u4e8e\u7f16\u5199\u5e93\u51fd\u6570\u548c API\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u51fd\u6570\u901a\u5e38\u4f1a\u88ab\u8bb8\u591a\u4e0d\u540c\u7684\u8c03\u7528\u8005\u4f7f\u7528\uff0c\u800c\u8c03\u7528\u8005\u4e0d\u9700\u8981\u5173\u5fc3\u6808\u7684\u6e05\u7406\u3002<\/p>\n<h3 id=\"\u9009\u62e9\u54ea\u79cd\u8c03\u7528\u7ea6\u5b9a\">\u9009\u62e9\u54ea\u79cd\u8c03\u7528\u7ea6\u5b9a\uff1f<\/h3>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>\u5982\u679c\u4f60\u6b63\u5728\u7f16\u5199\u4e00\u4e2a\u5e93\u6216 API\uff0c\u5e76\u4e14\u60f3\u8981\u786e\u4fdd\u6808\u7684\u5e73\u8861\u548c\u51cf\u5c11\u8c03\u7528\u8005\u7684\u8d1f\u62c5\uff0c\u90a3\u4e48 <code>__stdcall<\/code> \u53ef\u80fd\u662f\u66f4\u597d\u7684\u9009\u62e9\u3002<\/li>\n<li>\u5982\u679c\u4f60\u6b63\u5728\u7f16\u5199\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u4e14\u9700\u8981\u66f4\u5927\u7684\u7075\u6d3b\u6027\uff08\u4f8b\u5982\uff0c\u652f\u6301\u53ef\u53d8\u6570\u91cf\u7684\u53c2\u6570\uff09\uff0c\u90a3\u4e48 <code>__cdecl<\/code> \u53ef\u80fd\u66f4\u9002\u5408\u4f60\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u5728\u7f16\u5199\u8de8\u5e73\u53f0\u6216\u53ef\u79fb\u690d\u4ee3\u7801\u65f6\uff0c\u8fd8\u9700\u8981\u8003\u8651\u5176\u4ed6\u5e73\u53f0\u548c\u7f16\u8bd1\u5668\u53ef\u80fd\u4e0d\u652f\u6301\u8fd9\u4e9b\u7279\u5b9a\u7684\u8c03\u7528\u7ea6\u5b9a\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528\u6807\u51c6\u7684 C \u6216 C++ \u8c03\u7528\u7ea6\u5b9a\uff08\u901a\u5e38\u7b49\u540c\u4e8e <code>__cdecl<\/code>\uff09\u53ef\u80fd\u662f\u66f4\u597d\u7684\u9009\u62e9\u3002<\/p>\n<h2 id=\"\u56db\u79cdcast\">\u56db\u79cdCast<\/h2>\n<p><strong>\u95ee\uff1aC++\u4e2d\u56db\u79cdCast\u7684\u4f7f\u7528\u573a\u666f\u662f\u4ec0\u4e48\uff1f<\/strong><\/p>\n<h3 id=\"1-staticcast\">1. <code>static_cast<\/code><\/h3>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u7528\u4e8e\u57fa\u7840\u6570\u636e\u7c7b\u578b\u4e4b\u95f4\u7684\u8f6c\u6362\uff08\u5982int\u8f6cdouble\uff09\uff0c\u6267\u884c\u975e\u591a\u6001\u7c7b\u578b\u7684\u4e0a\u4e0b\u8f6c\u6362\uff08upcasting\u548cdowncasting\uff09\uff0c\u4ee5\u53ca\u6267\u884c\u7a7a\u6307\u9488\u548c\u7a7a\u6307\u9488\u7c7b\u578b\u7684\u8f6c\u6362\u3002<\/li>\n<li><strong>\u5b89\u5168\u6027<\/strong>\uff1a\u901a\u5e38\u8ba4\u4e3a\u662f\u5b89\u5168\u7684\uff0c\u56e0\u4e3a\u5b83\u5728\u7f16\u8bd1\u65f6\u4f1a\u68c0\u67e5\u8f6c\u6362\u7684\u5408\u6cd5\u6027\u3002<\/li>\n<li><strong>\u4f7f\u7528\u573a\u666f<\/strong>\uff1a\u5f53\u4f60\u9700\u8981\u5728\u57fa\u7840\u6570\u636e\u7c7b\u578b\u4e4b\u95f4\u8f6c\u6362\uff0c\u6216\u8005\u9700\u8981\u5728\u5177\u6709\u7ee7\u627f\u5173\u7cfb\u7684\u7c7b\u4e4b\u95f4\u8f6c\u6362\u65f6\uff08\u53ea\u8981\u8fd9\u79cd\u8f6c\u6362\u662f\u5b89\u5168\u7684\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3 id=\"2-dynamiccast\">2. <code>dynamic_cast<\/code><\/h3>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u4e3b\u8981\u7528\u4e8e\u6267\u884c\u5b89\u5168\u7684\u5411\u4e0b\u548c\u4fa7\u5411\u7c7b\u578b\u8f6c\u6362\uff0c\u4f1a\u5728\u8fd0\u884c\u65f6\u68c0\u67e5\u8f6c\u6362\u662f\u5426\u6709\u6548\u3002<\/li>\n<li><strong>\u5b89\u5168\u6027<\/strong>\uff1a\u662f\u6700\u5b89\u5168\u7684\u8f6c\u6362\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5728\u8fd0\u884c\u65f6\u8fdb\u884c\u7c7b\u578b\u68c0\u67e5\u3002<\/li>\n<li><strong>\u4f7f\u7528\u573a\u666f<\/strong>\uff1a\u5f53\u4f60\u9700\u8981\u5728\u8fd0\u884c\u65f6\u786e\u5b9a\u4e00\u4e2a\u5bf9\u8c61\u662f\u5426\u5c5e\u4e8e\u7279\u5b9a\u7684\u7c7b\uff0c\u5e76\u9700\u8981\u5b89\u5168\u5730\u6267\u884c\u5411\u4e0b\u6216\u4fa7\u5411\u8f6c\u6362\u65f6\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3 id=\"3-reinterpretcast\">3. <code>reinterpret_cast<\/code><\/h3>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u63d0\u4f9b\u6700\u4f4e\u7ea7\u522b\u7684\u7c7b\u578b\u8f6c\u6362\uff0c\u53ea\u662f\u7b80\u5355\u5730\u91cd\u65b0\u89e3\u91ca\u7ed9\u5b9a\u7684\u4f4d\u6a21\u5f0f\u3002<\/li>\n<li><strong>\u5b89\u5168\u6027<\/strong>\uff1a\u662f\u6700\u4e0d\u5b89\u5168\u7684\u8f6c\u6362\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4f1a\u8fdb\u884c\u4efb\u4f55\u7c7b\u578b\u68c0\u67e5\u6216\u8c03\u6574\u3002<\/li>\n<li><strong>\u4f7f\u7528\u573a\u666f<\/strong>\uff1a\u5728\u4e0e\u786c\u4ef6\u76f4\u63a5\u4ea4\u4e92\u3001\u5904\u7406\u4f4e\u7ea7\u6570\u636e\u7ed3\u6784\u6216\u9700\u8981\u6267\u884c\u975e\u5e38\u89c4\u7684\u8f6c\u6362\u65f6\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3 id=\"4-constcast\">4. <code>const_cast<\/code><\/h3>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>\u529f\u80fd<\/strong>\uff1a\u7528\u4e8e\u6dfb\u52a0\u6216\u5220\u9664\u7c7b\u578b\u7684const\u6216volatile\u9650\u5b9a\u7b26\uff0c\u4ece\u800c\u5141\u8bb8\u4fee\u6539\u672c\u5e94\u4e3aconst\u7684\u5bf9\u8c61\u3002<\/li>\n<li><strong>\u5b89\u5168\u6027<\/strong>\uff1a\u4f7f\u7528\u65f6\u9700\u8981\u8c28\u614e\uff0c\u56e0\u4e3a\u5b83\u53ef\u80fd\u7834\u574f\u6570\u636e\u7684\u5b8c\u6574\u6027\u3002<\/li>\n<li><strong>\u4f7f\u7528\u573a\u666f<\/strong>\uff1a\u5f53\u4f60\u786e\u5b9e\u9700\u8981\u4fee\u6539\u4e00\u4e2a\u672c\u5e94\u4e3aconst\u7684\u5bf9\u8c61\u65f6\uff08\u5c3d\u7ba1\u8fd9\u901a\u5e38\u662f\u4e0d\u63a8\u8350\u7684\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2 id=\"\u8bbe\u8ba1\u6a21\u5f0f\">\u8bbe\u8ba1\u6a21\u5f0f<\/h2>\n<p><strong>\u95ee\uff1a\u7528\u8fc7\u6216\u5f88\u719f\u6089\u7684\u8bbe\u8ba1\u6a21\u5f0f\u6709\u54ea\u4e9b\uff1f<\/strong><\/p>\n<p><a href=\"https:\/\/www.vanforever.com.cn\/?p=243\">\u8bbe\u8ba1\u6a21\u5f0f\u901f\u8bb0<\/a><\/p>\n<h2 id=\"\u7f16\u7801\">\u7f16\u7801<\/h2>\n<p><strong>\u95ee\uff1a\u7f16\u7801\u4e86\u89e3\u4e48\uff1funicode\u548cutf-8\u7684\u533a\u522b<\/strong><\/p>\n<p>\u7f16\u7801\u662f\u5c06\u4fe1\u606f\u3001\u6570\u636e\u7b49\u6309\u7167\u4e00\u5b9a\u89c4\u5219\u8f6c\u6362\u6210\u7279\u5b9a\u7684\u7b26\u53f7\u6216\u4ee3\u7801\uff0c\u4ee5\u4fbf\u4e8e\u4f20\u8f93\u3001\u5b58\u50a8\u548c\u5904\u7406\u3002\u5b83\u662f\u8ba1\u7b97\u673a\u79d1\u5b66\u3001\u901a\u4fe1\u6280\u672f\u3001\u4fe1\u606f\u5b89\u5168\u7b49\u9886\u57df\u4e2d\u7684\u4e00\u9879\u91cd\u8981\u6280\u672f\u3002\u7f16\u7801\u7684\u4e3b\u8981\u76ee\u7684\u662f\u5c06\u590d\u6742\u7684\u4fe1\u606f\u8f6c\u6362\u4e3a\u8ba1\u7b97\u673a\u53ef\u4ee5\u5904\u7406\u7684\u7b80\u5355\u7684\u6570\u5b57\u7f16\u7801\uff0c\u4ece\u800c\u4f7f\u4fe1\u606f\u66f4\u52a0\u9ad8\u6548\u5730\u4f20\u8f93\u548c\u5b58\u50a8\uff0c\u540c\u65f6\u4fdd\u62a4\u4fe1\u606f\u7684\u5b89\u5168\u6027\u548c\u5b8c\u6574\u6027\u3002<\/p>\n<p>Unicode\u548cUTF-8\u90fd\u662f\u4e0e\u7f16\u7801\u76f8\u5173\u7684\u6982\u5ff5\uff0c\u4f46\u5b83\u4eec\u4e4b\u95f4\u5b58\u5728\u660e\u663e\u7684\u533a\u522b\uff1a<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li><strong>\u5b9a\u4e49\u4e0e\u7528\u9014<\/strong>\uff1a<\/li>\n<\/ol>\n<ul>\n<li>Unicode\uff1a\u662f\u4e00\u79cd\u5b57\u7b26\u96c6\uff0c\u4e3a\u5168\u7403\u8303\u56f4\u5185\u7684\u6bcf\u4e2a\u5b57\u7b26\u5206\u914d\u4e00\u4e2a\u552f\u4e00\u7684\u6570\u5b57\u4ee3\u7801\u3002\u8fd9\u610f\u5473\u7740\u5b83\u53ef\u4ee5\u8868\u793a\u4e16\u754c\u4e0a\u5927\u90e8\u5206\u7684\u5b57\u7b26\u3002<\/li>\n<li>UTF-8\uff1a\u662f\u4e00\u79cd\u5bf9Unicode\u5b57\u7b26\u96c6\u8fdb\u884c\u7f16\u7801\u7684\u65b9\u5f0f\uff0c\u5b83\u5141\u8bb8\u4f7f\u7528\u53ef\u53d8\u957f\u5ea6\u7684\u5b57\u8282\u6765\u8868\u793a\u5b57\u7b26\u3002<\/li>\n<\/ul>\n<\/li>\n<li style=\"list-style-type: none;\">\n<ol start=\"2\">\n<li><strong>\u7f16\u7801\u65b9\u5f0f<\/strong>\uff1a<\/li>\n<\/ol>\n<ul>\n<li>Unicode\uff1a\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u7f16\u7801\u65b9\u5f0f\u6765\u5b9e\u73b0\uff0c\u4f8b\u5982UTF-8\u548cUTF-16\u3002<\/li>\n<li>UTF-8\uff1a\u662fUnicode\u7684\u4e00\u79cd\u5177\u4f53\u7f16\u7801\u5b9e\u73b0\u3002<\/li>\n<\/ul>\n<\/li>\n<li style=\"list-style-type: none;\">\n<ol start=\"3\">\n<li><strong>\u5b57\u7b26\u8303\u56f4\u4e0e\u5927\u5c0f<\/strong>\uff1a<\/li>\n<\/ol>\n<ul>\n<li>Unicode\uff1a\u5b57\u7b26\u5927\u5c0f\u56fa\u5b9a\u6216\u53ef\u53d8\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u5176\u7f16\u7801\u65b9\u5f0f\u3002<\/li>\n<li>UTF-8\uff1a\u5b57\u7b26\u7684\u5927\u5c0f\u662f\u53ef\u53d8\u7684\u3002\u4f8b\u5982\uff0c\u82f1\u6587\u5b57\u7b26\u901a\u5e38\u4f7f\u75281\u4e2a\u5b57\u8282\u8868\u793a\uff0c\u800c\u66f4\u590d\u6742\u7684\u5b57\u7b26\u53ef\u80fd\u9700\u8981\u66f4\u591a\u5b57\u8282\u3002<\/li>\n<\/ul>\n<\/li>\n<li style=\"list-style-type: none;\">\n<ol start=\"4\">\n<li><strong>\u517c\u5bb9\u6027<\/strong>\uff1a<\/li>\n<\/ol>\n<ul>\n<li>UTF-8\uff1a\u517c\u5bb9ASCII\u7f16\u7801\uff0c\u56e0\u6b64\u5b83\u5e38\u88ab\u7528\u4e8e\u7f51\u9875\u548c\u6587\u4ef6\u5b58\u50a8\u3002<\/li>\n<li>Unicode\uff1a\u4f5c\u4e3a\u4e00\u4e2a\u5e7f\u6cdb\u63a5\u53d7\u7684\u6807\u51c6\uff0c\u5b83\u53ef\u4ee5\u8868\u793a\u5927\u91cf\u7684\u5b57\u7b26\uff0c\u9002\u7528\u4e8e\u9700\u8981\u7edf\u4e00\u548c\u56fd\u9645\u5316\u7684\u5b57\u7b26\u5904\u7406\u573a\u666f\u3002<\/li>\n<\/ul>\n<\/li>\n<li style=\"list-style-type: none;\">\n<ol start=\"5\">\n<li><strong>\u5e94\u7528\u573a\u666f<\/strong>\uff1a<\/li>\n<\/ol>\n<ul>\n<li>UTF-8\uff1a\u7531\u4e8e\u5176\u53ef\u53d8\u957f\u5ea6\u548c\u4e0eASCII\u7684\u517c\u5bb9\u6027\uff0c\u5b83\u901a\u5e38\u66f4\u8282\u7701\u5b58\u50a8\u7a7a\u95f4\uff0c\u56e0\u6b64\u9002\u7528\u4e8e\u9700\u8981\u8282\u7701\u5b58\u50a8\u7a7a\u95f4\u5e76\u4fdd\u6301\u517c\u5bb9\u6027\u7684\u573a\u5408\u3002<\/li>\n<li>Unicode\uff1a\u5176\u5e7f\u6cdb\u7684\u5e94\u7528\u8303\u56f4\u4f7f\u5176\u9002\u7528\u4e8e\u5404\u79cd\u9700\u8981\u7edf\u4e00\u5b57\u7b26\u5904\u7406\u7684\u573a\u666f\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>C++\u9762\u7ecf\u8bb0\u5f55 const \u95ee:\u4e86\u89e3const\u4e48\uff1f\u54ea\u4e9b\u65f6\u5019\u7528\u5230const\uff1f\u4e0e\u5b8f\u5b9a\u4e49\u6709\u4ec0\u4e48\u5dee\u5f02\uff1f \u5f53\u7136\u4e86\u89e3con [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4],"class_list":["post-228","post","type-post","status-publish","format-standard","hentry","category-c","tag-c"],"_links":{"self":[{"href":"https:\/\/www.vanforever.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vanforever.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vanforever.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vanforever.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vanforever.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=228"}],"version-history":[{"count":15,"href":"https:\/\/www.vanforever.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/228\/revisions"}],"predecessor-version":[{"id":248,"href":"https:\/\/www.vanforever.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/228\/revisions\/248"}],"wp:attachment":[{"href":"https:\/\/www.vanforever.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vanforever.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vanforever.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}