{"id":397,"date":"2024-06-15T16:46:38","date_gmt":"2024-06-15T08:46:38","guid":{"rendered":"https:\/\/www.vanforever.com.cn\/?p=397"},"modified":"2024-06-15T16:46:38","modified_gmt":"2024-06-15T08:46:38","slug":"%e4%ba%86%e8%a7%a3const%e3%80%81%e6%8c%87%e9%92%88%e3%80%81%e5%bc%95%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.vanforever.com.cn\/?p=397","title":{"rendered":"\u4e86\u89e3Const\u3001\u6307\u9488\u3001\u5f15\u7528"},"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\/20240610\/wallhaven-exqg9w_3840x2400.png'><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\/20240610\/wallhaven-exqg9w_3840x2400.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" width=\"3840\" height=\"2400\" \/><\/div><\/div><\/div>\n<h1 id=\"\u4e86\u89e3const\u6307\u9488\u5f15\u7528\">\u4e86\u89e3Const\u3001\u6307\u9488\u3001\u5f15\u7528<\/h1>\n<h2 id=\"const\">const<\/h2>\n<ol start=\"\">\n<li><strong>\u5e38\u91cf\u5b9a\u4e49\u4e0e\u66ff\u6362<\/strong>\uff1a\n<ul>\n<li>\u4f7f\u7528 <code>const<\/code> \u5b9a\u4e49\u53d8\u91cf\u65f6\uff0c\u5982\u679c\u8d4b\u503c\u7684\u662f\u4e00\u4e2a\u7acb\u5373\u6570\uff08\u5b57\u9762\u91cf\uff09\uff0c\u5219\u8be5\u53d8\u91cf\u662f\u4e00\u4e2a\u5e38\u91cf\u3002\u7f16\u8bd1\u5668\u4f1a\u5728\u7f16\u8bd1\u65f6\u5c06\u6240\u6709\u7528\u5230\u8fd9\u4e2a\u5e38\u91cf\u7684\u5730\u65b9\u66ff\u6362\u4e3a\u5b83\u7684\u521d\u59cb\u503c\uff0c\u8fd9\u79f0\u4e3a\u5e38\u91cf\u6298\u53e0\u3002\u82e5\u60f3\u5728\u8fd0\u884c\u65f6\u6539\u53d8\u8fd9\u4e2a\u503c\uff0c\u9700\u8981\u4f7f\u7528 <code>volatile<\/code> \u5173\u952e\u5b57\uff0c\u8fd9\u4f1a\u544a\u8bc9\u7f16\u8bd1\u5668\u4e0d\u8981\u5bf9\u8fd9\u4e2a\u53d8\u91cf\u8fdb\u884c\u4f18\u5316\u3002<\/li>\n<li>\u5f53\u4ee5\u7f16\u8bd1\u65f6\u521d\u59cb\u5316\u7684\u65b9\u5f0f\u5b9a\u4e49\u4e00\u4e2aconst\u5bf9\u8c61\u65f6\uff0c\u7f16\u8bd1\u5668\u5c06\u5728\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u628a\u7528\u5230\u8be5\u53d8\u91cf\u7684\u5730\u65b9\u90fd\u66ff\u6362\u6210\u5bf9\u5e94\u7684\u503c\u3002\u6240\u4ee5\u5982\u679c\u60f3\u5728\u591a\u4e2a\u6587\u4ef6\u4e4b\u95f4\u5171\u4eabconst\u5bf9\u8c61\uff0c\u5fc5\u987b\u5728\u53d8\u91cf\u7684\u5b9a\u4e49\u4e4b\u524d\u6dfb\u52a0extern\u5173\u952e\u5b57\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u6210\u5458\u51fd\u6570\u7684 <code>const<\/code> \u4fee\u9970<\/strong>\uff1a\n<ul>\n<li>\u5f53 <code>const<\/code> \u7528\u5728\u6210\u5458\u51fd\u6570\u7684\u540e\u9762\u65f6\uff0c\u8868\u793a\u8be5\u6210\u5458\u51fd\u6570\u4e0d\u4f1a\u4fee\u6539\u7c7b\u7684\u4efb\u4f55\u6210\u5458\u53d8\u91cf\u3002\u8fd9\u88ab\u79f0\u4e3a\u5e38\u91cf\u6210\u5458\u51fd\u6570\u3002\u5b9e\u9645\u4e0a\uff0c\u5b83\u8868\u793a\u6210\u5458\u51fd\u6570\u4fdd\u8bc1\u4e0d\u4f1a\u4fee\u6539 <code>this<\/code> \u6307\u9488\u6307\u5411\u7684\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u6307\u9488\u4e0e <code>const<\/code><\/strong>\uff1a\n<ul>\n<li><code>const<\/code> \u53ef\u4ee5\u7528\u6765\u4fee\u9970\u6307\u9488\uff0c\u6839\u636e <code>const<\/code> \u4f4d\u7f6e\u7684\u4e0d\u540c\uff0c\u5206\u4e3a\u9876\u5c42 <code>const<\/code>\uff08\u6307\u9488\u5e38\u91cf\uff09\u548c\u5e95\u5c42 <code>const<\/code>\uff08\u5e38\u91cf\u6307\u9488\uff09\u3002<\/li>\n<li><strong>\u9876\u5c42 <code>const<\/code><\/strong>\uff1a\u8868\u793a\u6307\u9488\u672c\u8eab\u662f\u4e00\u4e2a\u5e38\u91cf\uff0c\u5373\u4e0d\u80fd\u6539\u53d8\u6307\u9488\u7684\u6307\u5411\u3002\u5e76\u4e0d\u610f\u5473\u7740\u4e0d\u80fd\u901a\u8fc7\u6307\u9488\u4fee\u6539\u5176\u6240\u6307\u5bf9\u8c61\u7684\u503c<\/li>\n<li><strong>\u5e95\u5c42 <code>const<\/code><\/strong>\uff1a\u8868\u793a\u6307\u9488\u6307\u5411\u7684\u662f\u4e00\u4e2a\u5e38\u91cf\uff0c\u5373\u4e0d\u80fd\u901a\u8fc7\u8fd9\u4e2a\u6307\u9488\u6539\u53d8\u6307\u5411\u5bf9\u8c61\u7684\u503c\u3002<strong>\u6ca1\u6709\u89c4\u5b9a\u5176\u6240\u6307\u5bf9\u8c61\u5fc5\u987b\u662f\u4e00\u4e2a\u5e38\u91cf<\/strong>\uff0c\u4ec5\u4ec5\u662f\u4e0d\u80fd\u901a\u8fc7\u8be5\u6307\u9488\u4fee\u6539\u5bf9\u8c61\u7684\u503c\uff0c\u4e5f\u5c31\u662f\u8bf4\u5bf9\u8c61\u7684\u503c\u53ef\u4ee5\u901a\u8fc7\u522b\u7684\u9014\u5f84\u6539\u53d8\u3002<\/li>\n<li>\u5e95\u5c42 <code>const<\/code> \u6307\u9488\u4e0d\u80fd\u8d4b\u503c\u7ed9\u975e\u5e38\u91cf\u6307\u9488\uff0c\u56e0\u4e3a\u8fd9\u53ef\u80fd\u4f1a\u5141\u8bb8\u901a\u8fc7\u975e\u5e38\u91cf\u6307\u9488\u4fee\u6539\u5e38\u91cf\u5bf9\u8c61\u7684\u503c\u3002<\/li>\n<li><strong>\u4e8c\u7ea7const<\/strong>(<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<\/li>\n<\/ol>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\u9876\u5c42const\u53ef\u4ee5\u8868\u793a\u4efb\u610f\u7684\u5bf9\u8c61\u662f\u5e38\u91cf\uff0c\u5e95\u5c42const\u5219\u4e0e\u6307\u9488\u548c\u5f15\u7528\u7b49\u590d\u5408\u7c7b\u578b\u90e8\u5206\u6709\u5173\u3002\u6240\u6709\u4fee\u9970\u5f15\u7528\u7684const\u90fd\u662f\u5e95\u5c42const\u3002<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">const int ci  = 42;\/\/\u4e0d\u80fd\u6539\u53d8ci\u7684\u503c\uff0c\u8fd9\u662f\u4e00\u4e2a\u9876\u5c42const\n<\/code><\/pre>\n<ol start=\"4\">\n<li><strong>\u5f15\u7528\u4e0econst<\/strong><\/li>\n<\/ol>\n<ul>\n<li>\u5e38\u91cf\u5f15\u7528\u7ed1\u5b9a\u975e\u5e38\u91cf\u662f<strong>\u5408\u6cd5<\/strong>\u7684\u884c\u4e3a\uff0c\u4f46\u662f<strong>\u4e0d\u5141\u8bb8<\/strong>\u901a\u8fc7\u5e38\u91cf\u5f15\u7528\u4fee\u6539\u975e\u5e38\u91cf<\/li>\n<\/ul>\n<ul>\n<li><code>const<\/code>\u5f15\u7528\u672c\u8eab\u4e0d\u80fd\u88ab\u7528\u4f5c\u5de6\u503c\uff0c\u5373\u4e0d\u80fd\u88ab\u8d4b\u503c\u3002\u8fd9\u662f\u56e0\u4e3a<code>const<\/code>\u5f15\u7528\u672c\u8eab\u662f\u5e38\u91cf\uff0c\u5176\u503c\u4e0d\u80fd\u6539\u53d8\u3002<\/li>\n<li>\u6ce8\u610f<strong>\u4e0d\u53ef\u4ee5\u628a\u5f15\u7528\u7ed1\u5230\u4e34\u65f6\u91cf<\/strong>\u4e0a<\/li>\n<\/ul>\n<ol start=\"5\">\n<li><strong>constexpr<\/strong><\/li>\n<\/ol>\n<p><strong>constexpr \u53d8\u91cf<\/strong><\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">constexpr int max_size = 10;  \/\/ max_size \u662f\u4e00\u4e2a\u7f16\u8bd1\u671f\u5e38\u91cf\n<\/code><\/pre>\n<p>\u8fd9\u91cc\uff0c<code>max_size<\/code> \u662f\u4e00\u4e2a <code>constexpr<\/code> \u53d8\u91cf\uff0c\u5b83\u7684\u503c\u5728\u7f16\u8bd1\u65f6\u5c31\u5df2\u7ecf\u786e\u5b9a\u3002<\/p>\n<p><strong>constexpr\u51fd\u6570<\/strong><\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">constexpr int get_max_size() {\n    return 10;  \/\/ \u8fd4\u56de\u4e00\u4e2a\u7f16\u8bd1\u671f\u5e38\u91cf\n}\n\nint main() {\n    constexpr int size = get_max_size();  \/\/ size \u4e5f\u662f\u4e00\u4e2a\u7f16\u8bd1\u671f\u5e38\u91cf\uff0c\u8fd9\u91cc\u7684\u524d\u63d0\u5728\u4e8eget_max_size()\u662f\u5e38\u91cf\u8868\u8fbe\u5f0f\n}\n<\/code><\/pre>\n<p><code>get_max_size()<\/code> \u662f\u4e00\u4e2a <code>constexpr<\/code> \u51fd\u6570\uff0c\u5b83\u7684\u8fd4\u56de\u503c\u5728\u7f16\u8bd1\u65f6\u5c31\u53ef\u4ee5\u786e\u5b9a\u3002\u56e0\u6b64\uff0c<code>size<\/code> \u4e5f\u662f\u4e00\u4e2a\u7f16\u8bd1\u671f\u5e38\u91cf\u3002<\/p>\n<p><strong>constexpr\u5bf9\u8c61<\/strong><\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">struct Point {\n    constexpr Point(int x, int y) : x(x), y(y) {}\n    int x, y;\n};\n\nconstexpr Point p1(3, 4);  \/\/ p1 \u662f\u4e00\u4e2a\u7f16\u8bd1\u671f\u5e38\u91cf\u5bf9\u8c61\n<\/code><\/pre>\n<p>\u5fc5\u987b\u6ce8\u610f\u4e00\u70b9\uff0c\u5728constexpr\u58f0\u660e\u4e2d\u5982\u679c\u5b9a\u4e49\u4e00\u4e2a\u6307\u9488\uff0c\u9650\u5b9a\u7b26constexpr\u4ec5\u4ec5\u5bf9\u6307\u9488\u6709\u6548\uff0c\u4e0e\u6307\u9488\u6240\u6307\u7684\u5bf9\u8c61\u65e0\u5173\u3002<\/p>\n<pre><code class=\"language-cpp\" lang=\"cpp\">constexpr int *q= nullptr \/\/\u8fd9\u91cc\u7684q\u662f\u4e00\u4e2a\u6307\u9488\u5e38\u91cf\nconstexpr int i = 42;\nconstexpr const int *p = &amp;i; \/\/\u8fd9\u91cc\u7684p\u662f\u4e8c\u7ea7const\n<\/code><\/pre>\n<h2 id=\"\u6307\u9488\u548c\u5f15\u7528\">\u6307\u9488\u548c\u5f15\u7528<\/h2>\n<ol start=\"\">\n<li>\u5f15\u7528\u5206\u4e3a<strong>\u5de6\u503c\u548c\u53f3\u503c<\/strong>\u8fd8\u6709<strong>\u4e07\u80fd\u5f15\u7528<\/strong><\/li>\n<li>\u5355\u8bf4\u5de6\u503c\u5f15\u7528\uff1a<\/li>\n<\/ol>\n<p>\uff081\uff09\u5f15\u7528\u53ef\u4ee5\u8bf4\u662f\u66f4\u5b89\u5168\u7684\u6307\u9488\uff0c\u4e24\u8005\u5b9a\u4e49\u548c\u4fee\u6539\u65f6\u7684\u6c47\u7f16\u6307\u4ee4\u4e00\u6837\u3002<\/p>\n<p>\uff082\uff09\u6307\u9488\u7684\u6307\u5411\u5728\u975e\u9876\u5c42const\u7684\u60c5\u51b5\u662f\u53ef\u53d8\u7684\uff0c\u5f15\u7528\u5c31\u50cf\u6307\u9488\u5e38\u91cf\uff0c\u4e0d\u53ef\u4fee\u6539\u6307\u5411\u3002\u6240\u4ee5\u5f15\u7528\u5fc5\u987b\u521d\u59cb\u5316\uff0c\u4e14\u4e0d\u80fd\u4e3a\u7a7a\uff0c\u800c\u6307\u9488\u53ef\u4ee5\u4e0d\u521d\u59cb\u5316\u548c\u6307\u5411\u7a7a\u3002<\/p>\n<p>\uff083\uff09\u6307\u9488\u53ef\u4ee5\u662f\u591a\u7ea7\u7684\uff0c\u5f15\u7528\u53ea\u80fd\u4e00\u7ea7<\/p>\n<p><strong>\u5de6\u503c\u5f15\u7528\u3001\u53f3\u503c\u5f15\u7528\uff1a<\/strong><\/p>\n<p>\u5148\u8bf4\u4e00\u4e0b\u5de6\u503c\uff0c\u53f3\u503c\u7684\u533a\u522b\uff1a<\/p>\n<p><strong>\u5de6\u503c<\/strong>\u662f\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0c\u6709\u660e\u786e\u5730\u5740\u7684\u6570\u636e\uff0c\u4e5f\u5c31\u662f\u8bf4\u53ef\u4ee5\u5bf9\u5176\u53d6\u5730\u5740\u3002<\/p>\n<p><strong>\u53f3\u503c<\/strong>\u4e0d\u53ef\u53d6\u5730\u5740\uff0c\u4f46\u53ef\u4ee5\u63d0\u4f9b\u6570\u636e\u503c\u7684\u6570\u636e\u6216\u8005\u662f\u5c06\u4ea1\u503c\u3002\u6bd4\u5982123\u8fd9\u79cd\u5e38\u6570\u6216\u8005\u662f\u51fd\u6570\u7684\u503c\u8fd4\u56de\u7c7b\u578b\u548cmove\u51fd\u6570\u3002<\/p>\n<p>\u533a\u5206\u5de6\u503c\u5f15\u7528\u548c\u53f3\u503c\u5f15\u7528\uff0c\u5176\u5b9e\u6211\u4eec\u53ef\u4ee5\u628a\u53f3\u503c\u5f15\u7528\u5f53\u6210\u5de6\u503c\u5f15\u7528\u7684\u8865\u4e01\uff1a<\/p>\n<p>\u5de6\u503c\u5f15\u7528\u7684\u4f5c\u7528\u662f\uff1a\u4f20\u53c2\u6216\u8005\u505a\u51fd\u6570\u8fd4\u56de\u503c\u65f6\uff0c\u4f7f\u7528\u5de6\u503c\u5f15\u7528\u53ef\u4ee5\u907f\u514d\u5bf9\u8c61\u8c03\u7528\u62f7\u8d1d\u6784\u9020\u3002<\/p>\n<p>\u4f46\u662f\u5462\uff0c\u5de6\u503c\u5f15\u7528\u6709\u8f83\u5927\u7684\u5c40\u9650\u6027\u3002<\/p>\n<p>\u5e38\u89c1\u7684\u6bd4\u5982\uff1a\u6211\u4eec\u8981vector\u6269\u5bb9\uff0c\u8981\u62f7\u8d1d\u91cc\u9762\u5b58\u7740\u7684\u5341\u4e07\u4e2a\u5143\u7d20\uff0c\u6216\u8005\u63a5\u53d7\u4e00\u4e2a\u8f83\u5927\u7684\u4e34\u65f6\u5bf9\u8c61\uff0c\u4ee5\u524d\u7684\u8bdd\u867d\u7136\u6709\u6df1\u62f7\u8d1d\u89e3\u51b3\u5185\u5b58\u91cd\u590d\u91ca\u653e\u7684\u95ee\u9898\uff0c\u4f46\u80af\u5b9a\u4f1a\u6d88\u8017\u5927\u91cf\u7684\u62f7\u8d1d\u65f6\u95f4\uff0c\u6027\u80fd\u6d6a\u8d39\uff0c\u800c\u4e14\u6700\u4e3b\u8981\u7684\u662f\u62f7\u8d1d\u5b8c\u8fd9\u4e9b\u4e1c\u897f\u5c31\u4e0d\u9700\u8981\u4e86\u3002<\/p>\n<p>\u6240\u4ee5\u53f3\u503c\u5f15\u7528\u5c31\u89e3\u51b3\u4e86\u8fd9\u4e2a\u95ee\u9898\uff0c\u800c\u4e14\u5728STL\u7684\u5bb9\u5668\u4e2d\uff0c\u5927\u91cf\u7684\u51fa\u73b0\u4e86\u53f3\u503c\u5f15\u7528\u4e3a\u53c2\u6570\u7684\u79fb\u52a8\u6784\u9020\u51fd\u6570\u548c\u5176\u4ed6\u51fd\u6570\uff0c\u6bd4\u5982vector\u7684push_back\uff0cemplace_back\u90fd\u80fd\u63a5\u53d7\u53f3\u503c\u4e86\uff0c\u907f\u514d\u4e86\u591a\u4e00\u6b21\u62f7\u8d1d\u6784\u9020\u7684\u5f00\u9500\uff0cunique_ptr\u56e0\u4e3a\u80fd\u62f7\u8d1d\u53f3\u503c\u800c\u66f4\u65b9\u4fbf\u4e86\uff0c\u6700\u91cd\u8981\u7684\u662f\u6269\u5bb9\u65f6\uff0c\u5927\u91cf\u7684\u5143\u7d20\u590d\u5236\uff0c\u800c\u73b0\u5728\u5462\uff0c\u53ea\u8981\u6211\u4eec\u7684\u7c7b\u4e2d\u7684\u79fb\u52a8\u6784\u9020\u51fd\u6570\u58f0\u660e\u4e3anoexcept\uff0c\u8fd9\u662f\u56e0\u4e3avector\u6269\u5bb9\u65f6\u8981\u5224\u65ad\uff0c\u5982\u679c\u5199\u4e86\u79fb\u52a8\u6784\u9020\u5e76\u4e14\u662fnoexcept\u65f6\uff0c\u5c31\u4f1a\u6328\u4e2a\u8c03\u7528\u79fb\u52a8\u6784\u9020\uff0c\u800c\u4e0d\u662f\u62f7\u8d1d\u6784\u9020\uff0c\u5f53\u5bf9\u8c61\u91cc\u6709\u5f88\u591a\u7684\u6210\u5458\u53d8\u91cf\u65f6\uff0c\u8fd9\u6837\u5c31\u5927\u5927\u7684\u8282\u7701\u4e86\u6027\u80fd\u5f00\u9500\u3002<\/p>\n<p>Move\u8fd9\u4e2a\u51fd\u6570\u5176\u5b9e\u975e\u5e38\u6709\u8ff7\u60d1\u6027\uff0c\u5b83\u5e76\u4e0d\u662f\u79fb\u52a8\uff0c\u4ec5\u4ec5\u662f\u7c7b\u578b\u8f6c\u6362\uff0c\u5176\u5b9e\u5e95\u5c42\u7684\u5b9e\u73b0\u5c31\u662fstatic_cast&lt;&amp;&amp;&gt;\u5f3a\u5236\u8f6c\u6362\u6210\u53f3\u503c\u3002\u56e0\u4e3astatic cast\u5728\u7f16\u8bd1\u671f\u95f4\u5c31\u5b8c\u6210\u4e86\uff0c\u6240\u4ee5\u8fd0\u884c\u65f6\u4e0d\u4f1a\u751f\u6210\u4efb\u4f55\u4ee3\u7801\uff0c\u8fde\u4e00\u4e2a\u5b57\u8282\u90fd\u4e0d\u4f1a\u751f\u6210\u3002<\/p>\n<p>\u800cforward\u548cmove\u53c8\u5f88\u50cf\uff0c\u5728\u666e\u901a\u60c5\u51b5\u4e0b\uff0c\u4e24\u8005\u7684\u8f6c\u6362\u662f\u4e00\u6837\u7684\uff0c\u90fd\u662f\u5f3a\u8f6c\u4e3a\u53f3\u503c\u3002\u4f46\u5728\u51fd\u6570\u6a21\u677f\u4e14\u6709\u5f15\u7528\u6298\u53e0\u7684\u65f6\u5019\uff0cMove\u662f\u5f3a\u5236\u628a\u4f20\u5165\u503c\u8f6c\u6362\u4e3a\u53f3\u503c\uff0c\u800cforward\u662f\u6839\u636e\u4f20\u5165\u53c2\u6570\u662f\u5de6\u503c\u8fd8\u662f\u53f3\u503c\uff0c\u8fd4\u56de\u5176\u4f20\u5165\u7684\u7c7b\u578b\u3002<\/p>\n<p>\u4e24\u8005\u90fd\u662f\u5148\u7528remove_reference\u53bb\u9664\u5f15\u7528\uff0c\u600e\u4e48\u53bb\u9664\u7684\u5462\uff0c\u5b9a\u4e49\u4e00\u4e2a\u7ed3\u6784\u4f53\u6a21\u677f\uff0c\u5728\u91cc\u9762\u91cd\u547d\u540d\u4e00\u4e0b\u53c2\u6570\u7c7b\u578b\u5373\u53ef\uff0c\u4e3a\u4ec0\u4e48\u8981\u53bb\u9664\u5f15\u7528\u5462\uff0c\u8fd9\u662f\u4e3a\u4e86\u4fdd\u8bc1static_cast\u7684\u53cc&amp;&amp;\u7b26\u53f7\u4f5c\u7528\u4e8e\u975e\u5f15\u7528\u7c7b\u578b\u4e0a\uff0c\u56e0\u4e3amove\u548cforward\u7684\u6a21\u677f\u90fd\u662f\u4e07\u80fd\u5f15\u7528\uff0c\u5982\u679c\u4f20\u5165\u7684\u53c2\u6570\u6070\u597d\u662f\u4e00\u4e2a\u5de6\u503c\u5f15\u7528\uff0c\u90a3\u4e48\u4e07\u80fd\u5f15\u7528\u5c31\u4f1a\u53d8\u6210\u5de6\u503c\u5f15\u7528\u3002<\/p>\n<p><strong>\u53f3\u503c\u5f15\u7528\u3001\u79fb\u52a8\u8bed\u4e49\u3001\u5b8c\u7f8e\u8f6c\u53d1\uff1a<\/strong><\/p>\n<p>\u4e07\u80fd\u5f15\u7528\u770b\u8d77\u6765\u548c\u53f3\u503c\u5f15\u7528\u4e00\u6837\u3002\u7ed9\u4e07\u80fd\u5f15\u7528\u4f20\u5de6\u503c\u65f6\uff0c\u5c31\u53d8\u6210\u4e86\u5de6\u503c\u5f15\u7528\uff0c\u4f20\u53f3\u503c\u53d8\u6210\u53f3\u503c\u5f15\u7528\u3002<\/p>\n<p><strong>\u4ec0\u4e48\u65f6\u5019\u4e0d\u4f1a\u6210\u4e3a\u4e07\u80fd\u5f15\u7528\u5462\uff1f<\/strong><\/p>\n<p>\u4f46\u4e07\u80fd\u5f15\u7528\u53ea\u5728\u51fd\u6570\u6a21\u677f\u4e2d\uff0c\u4e14\u53d1\u751f\u4e86\u6a21\u677f\u7c7b\u578b\u63a8\u65ad\u624d\u4f1a\u6709\uff0c\u8fd8\u4e0d\u80fd\u52a0const\u9650\u5b9a\u7b26\uff08volatile\uff1f\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3Const\u3001\u6307\u9488\u3001\u5f15\u7528 const \u5e38\u91cf\u5b9a\u4e49\u4e0e\u66ff\u6362\uff1a \u4f7f\u7528 const \u5b9a\u4e49\u53d8\u91cf\u65f6\uff0c\u5982\u679c\u8d4b\u503c\u7684\u662f\u4e00\u4e2a\u7acb\u5373\u6570 [&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-397","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\/397","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=397"}],"version-history":[{"count":1,"href":"https:\/\/www.vanforever.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/397\/revisions"}],"predecessor-version":[{"id":398,"href":"https:\/\/www.vanforever.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/397\/revisions\/398"}],"wp:attachment":[{"href":"https:\/\/www.vanforever.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vanforever.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vanforever.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}