{"id":105678,"date":"2026-09-15T20:17:22","date_gmt":"2026-09-15T12:17:22","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/105678.html"},"modified":"2026-09-15T20:17:22","modified_gmt":"2026-09-15T12:17:22","slug":"c-%e5%9f%ba%e7%a1%80%e5%85%a5%e9%97%a8%e7%af%87%ef%bc%88%e4%b8%89%ef%bc%89%ef%bc%9a%e5%86%85%e8%81%94%e5%87%bd%e6%95%b0%e4%b8%8e%e7%a9%ba%e6%8c%87%e9%92%88","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/105678.html","title":{"rendered":"C++ \u57fa\u7840\u5165\u95e8\u7bc7\uff08\u4e09\uff09\uff1a\u5185\u8054\u51fd\u6570\u4e0e\u7a7a\u6307\u9488"},"content":{"rendered":"<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\u4e00. \u5185\u8054\u51fd\u6570<\/li>\n<li>\n<ul>\n<li>1.1 \u5185\u8054\u51fd\u6570\u7684\u5b9a\u4e49<\/li>\n<li>1.2 \u5b8f\u51fd\u6570\u7684\u7f3a\u9677\u4e0e\u95ee\u9898<\/li>\n<li>1.3 \u5185\u8054\u51fd\u6570\u7684\u4f7f\u7528<\/li>\n<li>1.4 \u5185\u8054\u51fd\u6570\u7684\u5e95\u5c42\u7ec6\u8282<\/li>\n<li>1.5 \u5185\u8054\u51fd\u6570\u7684\u4f18\u7f3a\u70b9<\/li>\n<li>\n<ul>\n<li>1.5.1 \u5185\u8054\u5c55\u5f00\u7684\u95ee\u9898<\/li>\n<li>1.5.2 \u58f0\u660e\u4e0e\u5b9a\u4e49\u5206\u79bb<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u4e8c. nullptr&#xff08;c&#043;&#043;11\u65b0\u589e\u5185\u5bb9&#xff09;<\/li>\n<li>\n<ul>\n<li>2.1 \u4e3a\u4ec0\u4e48\u9700\u8981 nullptr ?<\/li>\n<li>2.2 nullptr \u662f\u4ec0\u4e48 ?<\/li>\n<li>2.3 \u91cd\u8f7d\u89e3\u6790\u4e2d\u7684\u8868\u73b0<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260915121719-6aa9374fbd7cf.jpg\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>\u4e00. \u5185\u8054\u51fd\u6570<\/h2>\n<h3>1.1 \u5185\u8054\u51fd\u6570\u7684\u5b9a\u4e49<\/h3>\n<p>\u7528 inline \u4fee\u9970\u7684\u51fd\u6570\u53eb\u505a\u5185\u8054\u51fd\u6570&#xff0c;\u7f16\u8bd1\u65f6 C&#043;&#043; \u7f16\u8bd1\u5668\u4f1a\u5728\u8c03\u7528\u7684\u5730\u65b9\u5c55\u5f00\u5185\u8054\u51fd\u6570&#xff0c;\u8fd9\u6837\u8c03\u7528\u5185\u8054\u51fd\u6570\u5c31\u4e0d\u9700\u8981\u5efa\u7acb\u6808\u5e27\u4e86&#xff0c;\u5c31\u53ef\u4ee5\u63d0\u9ad8\u6548\u7387\u3002 \u5185\u8054\u51fd\u6570\u7684\u51fa\u73b0\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u53d6\u4ee3\u4e86 C \u8bed\u8a00\u7684\u5b8f\u51fd\u6570\u3002<\/p>\n<h3>1.2 \u5b8f\u51fd\u6570\u7684\u7f3a\u9677\u4e0e\u95ee\u9898<\/h3>\n<p>\u5b8f\u51fd\u6570&#xff08;\u5e26\u53c2\u6570\u7684\u5b8f&#xff09;\u672c\u8d28\u4e0a\u662f\u9884\u5904\u7406\u9636\u6bb5\u7684\u6587\u672c\u66ff\u6362&#xff0c;\u800c\u4e0d\u662f\u8bed\u8a00\u5c42\u9762\u7684\u51fd\u6570\u3002\u8fd9\u4e00\u6839\u672c\u7279\u6027\u51b3\u5b9a\u4e86\u5b83\u6709\u4e00\u7cfb\u5217\u96be\u4ee5\u56de\u907f\u7684\u7f3a\u9677\u3002 1. \u76f4\u63a5\u6587\u672c\u66ff\u6362<\/p>\n<p>\u5b8f\u51fd\u6570\u7f16\u8bd1\u91c7\u7528\u76f4\u63a5\u6587\u672c\u66ff\u6362&#xff0c;\u7f3a\u4e4f\u7c7b\u578b\u68c0\u67e5&#xff0c;\u7c7b\u578b\u4e0d\u5b89\u5168\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ \u5b9e\u73b0\u4e00\u4e2aADD\u5b8f\u51fd\u6570\u7684\u5e38\u89c1\u95ee\u9898<\/span><br \/>\n<span class=\"token comment\">\/\/#define ADD(int a, int b) return a &#043; b;<\/span><br \/>\n<span class=\"token comment\">\/\/#define ADD(a, b) a &#043; b;<\/span><br \/>\n<span class=\"token comment\">\/\/#define ADD(a, b) (a &#043; b)<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u6b63\u786e\u7684\u5b8f\u5b9e\u73b0<\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name function\">ADD<\/span><span class=\"token expression\"><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">,<\/span> b<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#043;<\/span> <span class=\"token punctuation\">(<\/span>b<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><\/span><\/span><\/p>\n<p>\u8fd9\u91cc\u6211\u4eec\u9700\u8981\u89e3\u7b54\u5173\u4e8e\u5b8f\u7684\u4e00\u4e9b\u95ee\u9898<\/p>\n<p>\u4e3a\u4ec0\u4e48\u5b8f\u51fd\u6570\u4e0d\u80fd\u52a0\u5206\u53f7&#xff1f; \u4e3a\u4ec0\u4e48\u8981\u6709\u5916\u62ec\u53f7&#xff1f; \u4e3a\u4ec0\u4e48\u8981\u6709\u5185\u62ec\u53f7&#xff1f;<\/p>\n<ul>\n<li>\u5b8f\u51fd\u6570\u5728\u4f7f\u7528\u65f6\u4f1a\u8fdb\u884c\u5b8f\u66ff\u6362&#xff0c;\u5c06\u5b8f\u540d\u90e8\u5206\u5168\u90e8\u66ff\u6362\u4e3a\u5b8f\u4f53&#xff0c;\u5982\u679c\u5b8f\u4f53\u6709\u5206\u53f7&#xff0c;\u4f1a\u88ab\u4e00\u5757\u513f\u66ff\u6362\u8fdb\u53bb&#xff0c;\u4ea7\u751f\u7f16\u8bd1\u9519\u8bef\u3002<\/li>\n<\/ul>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name function\">MAX<\/span><span class=\"token expression\"><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">,<\/span>b<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">)<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">(<\/span>b<span class=\"token punctuation\">)<\/span><span class=\"token operator\">?<\/span><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">)<\/span><span class=\"token operator\">:<\/span><span class=\"token punctuation\">(<\/span>b<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/span><\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>cond<span class=\"token punctuation\">)<\/span><br \/>\n    x <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">MAX<\/span><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">,<\/span>b<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">else<\/span><br \/>\n    x <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/\u5c55\u5f00\u540e&#xff1a;<\/span><br \/>\n<span class=\"token comment\">\/*if (cond)<br \/>\n    x &#061; ((a)&gt;(b)?(a):(b));;<br \/>\nelse<br \/>\n    x &#061; 0;<br \/>\n*\/<\/span>   <\/p>\n<ul>\n<li>\u5916\u62ec\u53f7\u6307\u7684\u662f\u628a\u6574\u4e2a\u5b8f\u4f53\u5305\u8d77\u6765\u5b83\u7684\u4f5c\u7528\u662f&#xff1a;\u4fdd\u8bc1\u6574\u4e2a\u5b8f\u5c55\u5f00\u7ed3\u679c\u4f5c\u4e3a\u4e00\u4e2a\u6574\u4f53\u53c2\u4e0e\u5916\u90e8\u8868\u8fbe\u5f0f&#xff0c;\u4e0d\u88ab\u5916\u90e8\u8fd0\u7b97\u7b26\u62c6\u5f00\u3002<\/li>\n<\/ul>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name function\">ADD<\/span><span class=\"token expression\"><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">,<\/span>b<span class=\"token punctuation\">)<\/span> a<span class=\"token operator\">&#043;<\/span>b<\/span><\/span><br \/>\n<span class=\"token keyword\">int<\/span> r <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">2<\/span> <span class=\"token operator\">*<\/span> <span class=\"token function\">ADD<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/\u5c55\u5f00\u540e&#xff1a;<\/span><br \/>\n<span class=\"token comment\">\/\/int r &#061; 2 * 1 &#043; 2;<\/span><\/p>\n<p>\u7ed3\u679c\u662f 4&#xff0c;\u800c\u4e0d\u662f\u671f\u671b\u7684 6\u3002\u56e0\u4e3a * \u4f18\u5148\u7ea7\u9ad8\u4e8e &#043;&#xff0c;\u5b8f\u4f53\u88ab\u62c6\u5f00\u4e86\u3002<\/p>\n<p><span class=\"token comment\">\/\/\u52a0\u4e0a\u5916\u62ec\u53f7&#xff1a;<\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name function\">ADD<\/span><span class=\"token expression\"><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">,<\/span>b<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">)<\/span><span class=\"token operator\">&#043;<\/span><span class=\"token punctuation\">(<\/span>b<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><\/span><\/span><br \/>\n<span class=\"token keyword\">int<\/span> r <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">2<\/span> <span class=\"token operator\">*<\/span> <span class=\"token function\">ADD<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/\u5c55\u5f00&#xff1a;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> r <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">2<\/span> <span class=\"token operator\">*<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">&#043;<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u7ed3\u679c\u5c31\u662f 6\u3002\u6240\u4ee5\u5916\u62ec\u53f7\u4fdd\u62a4\u7684\u662f&#xff1a;\u5b8f\u6574\u4f53\u4e0e\u5916\u90e8\u8fd0\u7b97\u7b26\u4e4b\u95f4\u7684\u4f18\u5148\u7ea7\u5173\u7cfb\u3002<\/p>\n<ul>\n<li>\u5185\u62ec\u53f7\u6307\u7684\u662f\u628a\u6bcf\u4e2a\u53c2\u6570\u5728\u5b8f\u4f53\u5185\u90e8\u90fd\u5305\u8d77\u6765&#xff1a;#define MUL(a,b) ((a)*(b))&#xff0c;\u8fd9\u91cc\u7684 (a) \u548c (b) \u5c31\u662f\u5185\u62ec\u53f7\u3002\u5b83\u7684\u4f5c\u7528\u662f&#xff1a;\u4fdd\u8bc1\u5b9e\u53c2\u8868\u8fbe\u5f0f\u4f5c\u4e3a\u4e00\u4e2a\u6574\u4f53\u53c2\u4e0e\u5b8f\u4f53\u5185\u90e8\u7684\u8fd0\u7b97\u3002<\/li>\n<\/ul>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name function\">MUL<\/span><span class=\"token expression\"><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">,<\/span>b<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">(<\/span>a<span class=\"token operator\">*<\/span>b<span class=\"token punctuation\">)<\/span><\/span><\/span><br \/>\n<span class=\"token keyword\">int<\/span> r <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">MUL<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token operator\">&#043;<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/\u5c55\u5f00&#xff1a;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> r <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token operator\">&#043;<\/span><span class=\"token number\">2<\/span><span class=\"token operator\">*<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u7ed3\u679c\u662f 7&#xff0c;\u800c\u4e0d\u662f\u671f\u671b\u7684 9\u3002\u56e0\u4e3a 2*3 \u5148\u7b97\u4e86<\/p>\n<p><span class=\"token comment\">\/\/\u52a0\u4e0a\u5185\u62ec\u53f7&#xff1a;<\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">define<\/span> <span class=\"token macro-name function\">MUL<\/span><span class=\"token expression\"><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">,<\/span>b<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">)<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">(<\/span>b<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><\/span><\/span><br \/>\n<span class=\"token keyword\">int<\/span> r <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">MUL<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token operator\">&#043;<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/\u5c55\u5f00&#xff1a;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> r <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token operator\">&#043;<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u52a0\u4e0a\u5185\u62ec\u53f7\u7ed3\u679c\u624d\u662f 9\u3002 \u6240\u4ee5\u5185\u62ec\u53f7\u4fdd\u62a4\u7684\u662f&#xff1a;\u5b9e\u53c2\u8868\u8fbe\u5f0f\u4e0e\u5b8f\u4f53\u5185\u90e8\u8fd0\u7b97\u7b26\u4e4b\u95f4\u7684\u4f18\u5148\u7ea7\u5173\u7cfb\u3002<\/p>\n<p>\u62ec\u53f7\u53ea\u80fd\u89e3\u51b3\u4f18\u5148\u7ea7\u548c\u7ed3\u5408\u6027\u95ee\u9898&#xff0c;\u4e0d\u80fd\u89e3\u51b3\u5b8f\u51fd\u6570\u7684\u6839\u672c\u7f3a\u9677&#xff1a;\u53c2\u6570\u53ef\u80fd\u88ab\u591a\u6b21\u6c42\u503c&#xff0c;\u4f8b\u5982 MAX(i&#043;&#043;, j)&#xff1b;\u6ca1\u6709\u7c7b\u578b\u68c0\u67e5&#xff1b;\u8c03\u8bd5\u56f0\u96be&#xff1b;\u547d\u540d\u6c61\u67d3&#xff1b;\u4ee3\u7801\u81a8\u80c0\u3002<\/p>\n<p>\u6240\u4ee5\u73b0\u4ee3 C\/C&#043;&#043; \u4e2d&#xff0c;\u80fd\u4e0d\u7528\u51fd\u6570\u5f0f\u5b8f\u5c31\u4e0d\u7528\u3002\u4f18\u5148\u8003\u8651&#xff1a;C&#xff1a;static inline \u51fd\u6570&#xff1b;C&#043;&#043;&#xff1a;inline \u51fd\u6570\u3001constexpr \u51fd\u6570\u3001\u6a21\u677f\u3001lambda\u3002\u5b8f\u53ea\u4fdd\u7559\u7ed9\u90a3\u4e9b\u8bed\u8a00\u673a\u5236\u65e0\u6cd5\u66ff\u4ee3\u7684\u573a\u666f&#xff0c;\u6bd4\u5982\u6761\u4ef6\u7f16\u8bd1\u3001\u5b57\u7b26\u4e32\u5316\u3001\u8bb0\u53f7\u62fc\u63a5\u7b49\u3002<\/p>\n<h3>1.3 \u5185\u8054\u51fd\u6570\u7684\u4f7f\u7528<\/h3>\n<p>\u76f4\u63a5\u5728\u4e00\u4e2a\u51fd\u6570\u524d\u9762\u52a0\u4e0a inline \u5173\u952e\u5b57\u5373\u53ef\u3002<\/p>\n<p><span class=\"token keyword\">inline<\/span> <span class=\"token function\">Add<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> x<span class=\"token punctuation\">,<\/span><span class=\"token keyword\">int<\/span> y<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> a <span class=\"token operator\">&#061;<\/span> b <span class=\"token operator\">&#043;<\/span> c <span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> z <span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u5728 VS \u7f16\u8bd1\u5668\u7684 Debug \u7248\u672c\u4e0b\u9ed8\u8ba4\u4e0d\u5c55\u5f00 inline&#xff0c;\u8fd9\u6837\u65b9\u4fbf\u8c03\u8bd5\u3002\u82e5 Debug \u7248\u672c\u60f3\u5c55\u5f00&#xff0c;\u9700\u8981\u8bbe\u7f6e\u4ee5\u4e0b\u4e24\u4e2a\u5730\u65b9\u3002 \u5728\u9879\u76ee\u4e2d\u53f3\u952e\u5355\u51fb\u9879\u76ee&#xff0c;\u8fdb\u5165\u9879\u76ee\u5c5e\u6027&#xff1a; <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260915121720-6aa93750ad331.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> C\/C&#043;&#043; -&gt; \u8c03\u8bd5\u4fe1\u606f\u683c\u5f0f -&gt; \u7a0b\u5e8f\u6570\u636e\u5e93(\/Zi)<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260915121721-6aa937511b5e6.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> C\/C&#043;&#043; -&gt; \u4f18\u5316 -&gt; \u5185\u8054\u51fd\u6570\u6269\u5c55 -&gt; \u53ea\u9002\u7528\u4e8e_inline(\/Ob1)<\/p>\n<p>\u8fd9\u6837\u7f16\u8bd1\u5668\u5c31\u53ef\u4ee5\u5c06\u5185\u8054\u51fd\u6570\u5c55\u5f00\u4ee5\u63d0\u5347\u8fd0\u884c\u6548\u7387\u4e86\u3002<\/p>\n<h3>1.4 \u5185\u8054\u51fd\u6570\u7684\u5e95\u5c42\u7ec6\u8282<\/h3>\n<p>inline \u5bf9\u4e8e\u7f16\u8bd1\u5668\u800c\u8a00\u53ea\u662f\u4e00\u4e2a\u5efa\u8bae&#xff0c;\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u4f60\u52a0\u4e86 inline \u7f16\u8bd1\u5668\u4e5f\u53ef\u4ee5\u9009\u62e9\u5728\u8c03\u7528\u7684\u5730\u65b9\u4e0d\u5c55\u5f00&#xff0c;\u4e0d\u540c\u7f16\u8bd1\u5668\u5173\u4e8e inline \u7684\u5c55\u5f00\u5404\u4e0d\u76f8\u540c&#xff0c;\u56e0\u4e3a C&#043;&#043; \u6807\u51c6\u6ca1\u6709\u89c4\u5b9a\u8fd9\u4e2a\u3002inline \u9002\u7528\u4e8e\u9891\u7e41\u8c03\u7528\u7684\u77ed\u5c0f\u51fd\u6570&#xff0c;\u5bf9\u4e8e\u9012\u5f52\u51fd\u6570\u3001\u4ee3\u7801\u76f8\u5bf9\u591a\u4e00\u4e9b\u7684\u51fd\u6570&#xff0c;\u52a0\u4e0a inline \u4e5f\u4f1a\u88ab\u7f16\u8bd1\u5668\u5ffd\u7565\u3002<\/p>\n<h3>1.5 \u5185\u8054\u51fd\u6570\u7684\u4f18\u7f3a\u70b9<\/h3>\n<h4>1.5.1 \u5185\u8054\u5c55\u5f00\u7684\u95ee\u9898<\/h4>\n<p>\u6839\u636e\u4e0a\u6587&#xff0c;\u6211\u4eec\u77e5\u9053&#xff0c;\u5c55\u5f00\u53ef\u4ee5\u7701\u53bb\u51fd\u6570\u8c03\u7528\u7b49\u4e00\u7cfb\u5217\u590d\u6742\u64cd\u4f5c\u3002\u4ece\u800c\u63d0\u5347\u51fd\u6570\u7684\u8fd0\u884c\u6548\u7387\u3002\u867d\u7136\u5c55\u5f00\u540c\u65f6\u4f1a\u5f71\u54cd\u7f16\u8bd1\u901f\u5ea6&#xff0c;\u4f46\u662f\u201c\u5bf9\u51fd\u6570\u8fd0\u884c\u6548\u7387\u7684\u63d0\u5347\u201d\u5bf9\u6bd4\u201c\u5bf9\u51fd\u6570\u7f16\u8bd1\u901f\u5ea6\u7684\u4e0b\u964d\u201d\u7684\u5f71\u54cd\u59cb\u7ec8\u8981\u5927\u3002<\/p>\n<p>\u5c55\u5f00\u80fd\u63d0\u5347\u6548\u7387&#xff0c;\u4f46\u5c55\u5f00\u4e0d\u662f\u7edd\u5bf9\u597d\u3002\u7f16\u8bd1\u5668\u5e76\u4e0d\u4f1a\u5bf9 inline \u8a00\u542c\u8ba1\u4ece\u3002\u8bbe\u60f3\u4e00\u4e2a\u6781\u7aef\u573a\u666f&#xff1a;\u67d0\u5185\u8054\u51fd\u6570\u6709 100 \u6761\u8bed\u53e5&#xff0c;\u9879\u76ee\u4e2d\u6709 10000 \u4e2a\u8c03\u7528\u70b9\u3002\u82e5\u6bcf\u6761\u8bed\u53e5\u7f16\u8bd1\u540e\u5e73\u5747 6 \u5b57\u8282&#xff0c;\u5168\u90e8\u5c55\u5f00\u5c06\u589e\u52a0\u7ea6 100 \u4e07\u6761\u6307\u4ee4\u3001\u7ea6 6 MB \u673a\u5668\u7801&#xff0c;\u5bf9\u5b89\u88c5\u5305\u548c\u6307\u4ee4\u7f13\u5b58\u90fd\u662f\u707e\u96be\u3002\u4f46\u73b0\u5b9e\u4e2d&#xff0c;\u7f16\u8bd1\u5668\u51e0\u4e4e\u4e0d\u4f1a\u5185\u8054\u8fd9\u6837\u7684\u51fd\u6570&#xff1a;\u6210\u672c\u6a21\u578b\u4f1a\u56e0\u51fd\u6570\u4f53\u8fc7\u5927\u3001\u8c03\u7528\u70b9\u8fc7\u591a\u800c\u62d2\u7edd\u3002inline \u53ea\u662f\u63d0\u793a&#xff0c;\u4e0d\u662f\u547d\u4ee4\u3002\u771f\u6b63\u80fd\u9020\u6210\u8fd9\u79cd\u81a8\u80c0\u7684&#xff0c;\u901a\u5e38\u662f __forceinline\u3001always_inline \u7b49\u5f3a\u5236\u624b\u6bb5\u3002\u5408\u7406\u4f7f\u7528\u4e0b&#xff0c;\u53ea\u5bf9\u77ed\u5c0f\u70ed\u51fd\u6570\u5185\u8054&#xff0c;\u7f3a\u70b9\u53ef\u4ee5\u5c0f\u5230\u53ef\u5ffd\u7565\u3002\u7f16\u8bd1\u5668\u4f1a\u5e2e\u52a9\u4f60\u5408\u7406\u4f7f\u7528\u5185\u8054&#xff0c;\u4f46\u524d\u63d0\u662f&#xff1a;\u4f60\u7ed9\u5b83\u51b3\u7b56\u7a7a\u95f4&#xff0c;\u800c\u4e0d\u662f\u66ff\u5b83\u505a\u51b3\u5b9a\u3002<\/p>\n<h4>1.5.2 \u58f0\u660e\u4e0e\u5b9a\u4e49\u5206\u79bb<\/h4>\n<p>\u5185\u8054\u51fd\u6570\u4e0d\u53ef\u4ee5\u8fdb\u884c\u58f0\u660e\u548c\u5b9a\u4e49\u5206\u79bb\u3002\u5982\u679c\u5206\u79bb&#xff0c;\u5185\u8054\u51fd\u6570\u7684\u8c03\u7528\u70b9\u5c06\u627e\u4e0d\u5230\u5185\u8054\u51fd\u6570\u672c\u4f53<\/p>\n<p>\u5185\u8054\u51fd\u6570\u4e0d\u80fd\u50cf\u666e\u901a\u51fd\u6570\u90a3\u6837\u8fdb\u884c\u8de8\u7ffb\u8bd1\u5355\u5143\u7684\u58f0\u660e\u4e0e\u5b9a\u4e49\u5206\u79bb\u3002\u666e\u901a\u51fd\u6570\u53ea\u9700\u5728\u5934\u6587\u4ef6\u4e2d\u58f0\u660e&#xff0c;\u5b9a\u4e49\u53ef\u4ee5\u653e\u5728\u67d0\u4e2a .cpp \u4e2d&#xff0c;\u7531\u94fe\u63a5\u5668\u89e3\u6790\u7b26\u53f7&#xff1b;\u4f46\u5185\u8054\u51fd\u6570\u9700\u8981\u5728\u8c03\u7528\u70b9\u5c55\u5f00\u51fd\u6570\u4f53&#xff0c;\u7f16\u8bd1\u5668\u5728\u7f16\u8bd1\u6bcf\u4e2a\u7ffb\u8bd1\u5355\u5143\u65f6\u90fd\u5fc5\u987b\u770b\u5230\u5b8c\u6574\u5b9a\u4e49\u3002C&#043;&#043; \u6807\u51c6\u4e5f\u660e\u786e\u8981\u6c42&#xff1a;\u5185\u8054\u51fd\u6570\u5728\u6bcf\u4e2a\u4f7f\u7528\u5b83\u7684\u7ffb\u8bd1\u5355\u5143\u4e2d\u90fd\u5fc5\u987b\u6709\u5b9a\u4e49\u3002\u56e0\u6b64&#xff0c;\u5185\u8054\u51fd\u6570\u901a\u5e38\u76f4\u63a5\u5b9a\u4e49\u5728\u5934\u6587\u4ef6\u4e2d&#xff0c;\u800c\u4e0d\u662f\u53ea\u5728\u5934\u6587\u4ef6\u91cc\u653e\u58f0\u660e\u3001\u5728 .cpp \u91cc\u653e\u5b9a\u4e49\u3002\u82e5\u58f0\u660e\u548c\u5b9a\u4e49\u5199\u5728\u540c\u4e00\u4e2a\u7ffb\u8bd1\u5355\u5143\u5185&#xff0c;\u8bed\u6cd5\u4e0a\u53ef\u4ee5\u5206\u5f00&#xff1b;\u4f46\u5b9a\u4e49\u5fc5\u987b\u5bf9\u4f7f\u7528\u5b83\u7684\u7ffb\u8bd1\u5355\u5143\u53ef\u89c1\u3002\u7c7b\u5185\u5b9a\u4e49\u7684\u6210\u5458\u51fd\u6570\u9690\u5f0f\u5185\u8054&#xff0c;\u5929\u7136\u6ee1\u8db3\u8fd9\u4e00\u70b9\u3002C \u8bed\u8a00\u4e2d\u5219\u5e38\u7528 static inline \u628a\u5934\u6587\u4ef6\u5185\u8054\u51fd\u6570\u5b9a\u4e49\u4e3a\u5185\u90e8\u94fe\u63a5&#xff0c;\u4ee5\u907f\u514d\u94fe\u63a5\u548c ODR \u95ee\u9898\u3002<\/p>\n<h2>\u4e8c. nullptr&#xff08;c&#043;&#043;11\u65b0\u589e\u5185\u5bb9&#xff09;<\/h2>\n<p>nullptr \u662f C&#043;&#043;11 \u5f15\u5165\u7684\u7a7a\u6307\u9488\u5e38\u91cf&#xff0c;\u7528\u6765\u66ff\u4ee3 C\/C&#043;&#043; \u4e2d\u957f\u671f\u4f7f\u7528\u7684 NULL \u548c\u5b57\u9762\u91cf 0\u3002\u5b83\u7684\u76ee\u6807\u5f88\u660e\u786e&#xff1a;\u8ba9\u201c\u7a7a\u6307\u9488\u201d\u5728\u7c7b\u578b\u7cfb\u7edf\u91cc\u6709\u81ea\u5df1\u72ec\u7acb\u7684\u8eab\u4efd&#xff0c;\u800c\u4e0d\u662f\u4f2a\u88c5\u6210\u6574\u6570\u3002<\/p>\n<h3>2.1 \u4e3a\u4ec0\u4e48\u9700\u8981 nullptr ?<\/h3>\n<p>\u5728 C&#043;&#043;11 \u4e4b\u524d&#xff0c;\u8868\u793a\u7a7a\u6307\u9488\u901a\u5e38\u6709\u4e24\u79cd\u65b9\u5f0f&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> p <span class=\"token operator\">&#061;<\/span> <span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> q <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u4f46 NULL \u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u5b8f&#xff0c;\u5728 C&#043;&#043; \u4e2d\u901a\u5e38\u88ab\u5b9a\u4e49\u4e3a 0 \u6216 0L\u3002\u8fd9\u610f\u5473\u7740\u5b83\u9996\u5148\u662f\u4e00\u4e2a\u6574\u6570&#xff0c;\u53ea\u662f\u6070\u597d\u80fd\u9690\u5f0f\u8f6c\u6362\u6210\u6307\u9488\u3002\u8fd9\u4f1a\u5e26\u6765\u91cd\u8f7d\u89e3\u6790\u95ee\u9898&#xff1a;<\/p>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token function\">f<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">f<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">void<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token function\">f<\/span><span class=\"token punctuation\">(<\/span><span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u53ef\u80fd\u8c03\u7528 f(int)&#xff0c;\u4e5f\u53ef\u80fd\u6b67\u4e49&#xff0c;\u53d6\u51b3\u4e8e NULL \u7684\u5b9a\u4e49<\/span><br \/>\n<span class=\"token function\">f<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/ \u4e00\u5b9a\u8c03\u7528 f(int)<\/span><\/p>\n<p>\u7a0b\u5e8f\u5458\u60f3\u8868\u8fbe\u201c\u7a7a\u6307\u9488\u201d&#xff0c;\u7f16\u8bd1\u5668\u5374\u53ef\u80fd\u7406\u89e3\u6210\u201c\u6574\u6570 0\u201d\u3002nullptr \u89e3\u51b3\u4e86\u8fd9\u4e2a\u95ee\u9898<\/p>\n<p><span class=\"token function\">f<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">nullptr<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u660e\u786e\u8c03\u7528 f(void*)<\/span><\/p>\n<h3>2.2 nullptr \u662f\u4ec0\u4e48 ?<\/h3>\n<p>nullptr \u662f\u4e00\u4e2a\u5173\u952e\u5b57&#xff0c;\u7c7b\u578b\u662f std::nullptr_t&#xff0c;\u5b9a\u4e49\u5728 &lt;cstddef&gt; \u4e2d\u3002<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;cstddef&gt;<\/span><\/span><br \/>\nstd<span class=\"token double-colon punctuation\">::<\/span>nullptr_t n <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">nullptr<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5b83\u7684\u5173\u952e\u7279\u6027&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u662f\u7a7a\u6307\u9488\u5e38\u91cf&#xff0c;\u4e0d\u662f\u6574\u6570&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u53ef\u4ee5\u9690\u5f0f\u8f6c\u6362\u4e3a\u4efb\u610f\u6307\u9488\u7c7b\u578b&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u53ef\u4ee5\u9690\u5f0f\u8f6c\u6362\u4e3a\u4efb\u610f\u6210\u5458\u6307\u9488\u7c7b\u578b&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u53ef\u4ee5\u8f6c\u6362\u4e3a bool&#xff0c;\u503c\u4e3a false&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u80fd\u9690\u5f0f\u8f6c\u6362\u4e3a\u6574\u6570\u7c7b\u578b\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p><span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span> p <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">nullptr<\/span><span class=\"token punctuation\">;<\/span>          <span class=\"token comment\">\/\/ OK<\/span><br \/>\n<span class=\"token keyword\">double<\/span><span class=\"token operator\">*<\/span> q <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">nullptr<\/span><span class=\"token punctuation\">;<\/span>       <span class=\"token comment\">\/\/ OK<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">*<\/span>fp<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">nullptr<\/span><span class=\"token punctuation\">;<\/span>    <span class=\"token comment\">\/\/ OK<\/span><br \/>\n<span class=\"token keyword\">int<\/span> A<span class=\"token double-colon punctuation\">::<\/span><span class=\"token operator\">*<\/span>mp <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">nullptr<\/span><span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/ OK&#xff0c;\u6210\u5458\u6307\u9488<\/span><\/p>\n<p><span class=\"token keyword\">bool<\/span> b <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">nullptr<\/span><span class=\"token punctuation\">;<\/span>          <span class=\"token comment\">\/\/ OK&#xff0c;b &#061;&#061; false<\/span><br \/>\n<span class=\"token keyword\">int<\/span> x <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">nullptr<\/span><span class=\"token punctuation\">;<\/span>           <span class=\"token comment\">\/\/ \u9519\u8bef&#xff1a;\u4e0d\u80fd\u628a nullptr \u5f53\u6574\u6570<\/span><\/p>\n<h3>2.3 \u91cd\u8f7d\u89e3\u6790\u4e2d\u7684\u8868\u73b0<\/h3>\n<p>\u8fd9\u662f nullptr \u6700\u76f4\u89c2\u7684\u4ef7\u503c&#xff1a;<\/p>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token function\">f<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">f<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">void<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token function\">f<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>        <span class=\"token comment\">\/\/ \u8c03\u7528 f(int)<\/span><br \/>\n<span class=\"token function\">f<\/span><span class=\"token punctuation\">(<\/span><span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/ \u53ef\u80fd\u8c03\u7528 f(int)&#xff0c;\u4e5f\u53ef\u80fd\u6b67\u4e49<\/span><br \/>\n<span class=\"token function\">f<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">nullptr<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u8c03\u7528 f(void*)<\/span><\/p>\n<p>\u56e0\u4e3a nullptr \u4e0d\u80fd\u8f6c\u6210 int&#xff0c;\u4f46\u53ef\u4ee5\u8f6c\u6210 void*&#xff0c;\u6240\u4ee5\u5b83\u5929\u7136\u504f\u5411\u6307\u9488\u91cd\u8f7d\u3002<\/p>\n<p>\u603b\u7ed3&#xff1a;nullptr \u4e0d\u662f\u6307\u9488&#xff0c;\u800c\u662f\u7a7a\u6307\u9488\u5e38\u91cf&#xff0c;\u7c7b\u578b\u4e3a std::nullptr_t\u3002\u5b83\u53ef\u4ee5\u9690\u5f0f\u8f6c\u6362\u4e3a\u4efb\u610f\u6307\u9488\u548c\u6210\u5458\u6307\u9488&#xff0c;\u8f6c\u6362\u4e3a bool \u65f6\u4e3a false&#xff0c;\u4f46\u4e0d\u80fd\u8f6c\u6362\u4e3a\u6574\u6570\u3002\u5b83\u7684\u51fa\u73b0\u8ba9\u7a7a\u6307\u9488\u5728\u91cd\u8f7d\u89e3\u6790\u3001\u6a21\u677f\u63a8\u5bfc\u548c\u7c7b\u578b\u5b89\u5168\u4e0a\u90fd\u6709\u4e86\u660e\u786e\u8bed\u4e49&#xff0c;\u662f C&#043;&#043;11 \u4e2d\u66ff\u4ee3 NULL \u548c 0 \u7684\u6807\u51c6\u505a\u6cd5\u3002\u5199\u73b0\u4ee3 C&#043;&#043; \u65f6&#xff0c;\u8868\u793a\u7a7a\u6307\u9488&#xff0c;\u5c31\u7528 nullptr\u3002<\/p>\n<p>\u5185\u8054\u51fd\u6570\u4e0e\u7a7a\u6307\u9488&#xff0c;\u4e00\u4e2a\u8c08\u7f16\u8bd1\u671f\u7684\u5c55\u5f00\u4e0e\u53d6\u820d&#xff0c;\u4e00\u4e2a\u8c08\u8fd0\u884c\u65f6\u7684\u7a7a\u503c\u8fb9\u754c\u3002\u5b83\u4eec\u770b\u4f3c\u4e0d\u76f8\u5e72&#xff0c;\u5374\u90fd\u5728\u63d0\u9192\u6211\u4eec&#xff1a;C&#043;&#043; \u7684\u6548\u7387\u4e0e\u5b89\u5168&#xff0c;\u4ece\u6765\u4e0d\u662f\u81ea\u52a8\u83b7\u5f97\u7684&#xff0c;\u800c\u662f\u5efa\u7acb\u5728\u5bf9\u5e95\u5c42\u8bed\u4e49\u7684\u7406\u89e3\u4e4b\u4e0a\u3002\u81f3\u6b64&#xff0c;\u8fd9\u4e24\u4e2a\u8bdd\u9898\u544a\u4e00\u6bb5\u843d\u3002<\/p>\n<p>\u63a5\u4e0b\u6765&#xff0c;\u6211\u4eec\u5c06\u8d70\u8fdb\u7c7b\u548c\u5bf9\u8c61\u3002\u90a3\u662f C&#043;&#043; \u5c01\u88c5\u3001\u62bd\u8c61\u4e0e\u591a\u6001\u7684\u8d77\u70b9&#xff0c;\u4e5f\u662f this \u6307\u9488\u3001\u6784\u9020\u4e0e\u6790\u6784\u3001\u62f7\u8d1d\u4e0e\u79fb\u52a8\u7b49\u65b0\u95ee\u9898\u7684\u821e\u53f0\u3002\u5185\u8054\u4e0e\u7a7a\u6307\u9488\u4e0d\u4f1a\u6d88\u5931&#xff0c;\u5b83\u4eec\u4f1a\u4ee5\u6210\u5458\u51fd\u6570\u3001\u5bf9\u8c61\u751f\u547d\u5468\u671f\u7b49\u65b0\u7684\u5f62\u5f0f\u518d\u6b21\u51fa\u73b0\u3002\u8ba9\u6211\u4eec\u7ee7\u7eed\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260915121721-6aa9375175a15.jpg\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u76ee\u5f55\u4e00. \u5185\u8054\u51fd\u65701.1 \u5185\u8054\u51fd\u6570\u7684\u5b9a\u4e491.2 \u5b8f\u51fd\u6570\u7684\u7f3a\u9677\u4e0e\u95ee\u98981.3 \u5185\u8054\u51fd\u6570\u7684\u4f7f\u75281.4 \u5185\u8054\u51fd\u6570\u7684\u5e95\u5c42\u7ec6\u82821.5 \u5185\u8054\u51fd\u6570\u7684\u4f18\u7f3a\u70b91.5.1 \u5185\u8054\u5c55\u5f00\u7684\u95ee\u98981.5.2 \u58f0\u660e\u4e0e\u5b9a\u4e49\u5206\u79bb\u4e8c. nullptr&#xff08;c11\u65b0\u589e\u5185\u5bb9&#xff09;2.1 \u4e3a\u4ec0\u4e48\u9700\u8981 nullptr ?2.2 nullptr \u662f\u4ec0\u4e48 ?2.3 \u91cd\u8f7d\u89e3\u6790\u4e2d\u7684\u8868\u73b0\u4e00. \u5185\u8054\u51fd\u6570<br \/>\n1.1 \u5185\u8054\u51fd\u6570\u7684\u5b9a\u4e49<br \/>\n\u7528 inline \u4fee\u9970\u7684\u51fd\u6570\u53eb\u505a\u5185\u8054\u51fd\u6570&#xff0c;\u7f16\u8bd1\u65f6 C \u7f16\u8bd1\u5668\u4f1a\u5728\u8c03<\/p>\n","protected":false},"author":2,"featured_media":105674,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[11979,11980,11978,11653,55],"topic":[],"class_list":["post-105678","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-nullptr","tag-11980","tag-11978","tag-11653","tag-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C++ \u57fa\u7840\u5165\u95e8\u7bc7\uff08\u4e09\uff09\uff1a\u5185\u8054\u51fd\u6570\u4e0e\u7a7a\u6307\u9488 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/105678.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++ \u57fa\u7840\u5165\u95e8\u7bc7\uff08\u4e09\uff09\uff1a\u5185\u8054\u51fd\u6570\u4e0e\u7a7a\u6307\u9488 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u76ee\u5f55\u4e00. \u5185\u8054\u51fd\u65701.1 \u5185\u8054\u51fd\u6570\u7684\u5b9a\u4e491.2 \u5b8f\u51fd\u6570\u7684\u7f3a\u9677\u4e0e\u95ee\u98981.3 \u5185\u8054\u51fd\u6570\u7684\u4f7f\u75281.4 \u5185\u8054\u51fd\u6570\u7684\u5e95\u5c42\u7ec6\u82821.5 \u5185\u8054\u51fd\u6570\u7684\u4f18\u7f3a\u70b91.5.1 \u5185\u8054\u5c55\u5f00\u7684\u95ee\u98981.5.2 \u58f0\u660e\u4e0e\u5b9a\u4e49\u5206\u79bb\u4e8c. nullptr&#xff08;c11\u65b0\u589e\u5185\u5bb9&#xff09;2.1 \u4e3a\u4ec0\u4e48\u9700\u8981 nullptr ?2.2 nullptr \u662f\u4ec0\u4e48 ?2.3 \u91cd\u8f7d\u89e3\u6790\u4e2d\u7684\u8868\u73b0\u4e00. \u5185\u8054\u51fd\u6570 1.1 \u5185\u8054\u51fd\u6570\u7684\u5b9a\u4e49 \u7528 inline \u4fee\u9970\u7684\u51fd\u6570\u53eb\u505a\u5185\u8054\u51fd\u6570&#xff0c;\u7f16\u8bd1\u65f6 C \u7f16\u8bd1\u5668\u4f1a\u5728\u8c03\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/105678.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-15T12:17:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260915121719-6aa9374fbd7cf.jpg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/105678.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/105678.html\",\"name\":\"C++ \u57fa\u7840\u5165\u95e8\u7bc7\uff08\u4e09\uff09\uff1a\u5185\u8054\u51fd\u6570\u4e0e\u7a7a\u6307\u9488 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-15T12:17:22+00:00\",\"dateModified\":\"2026-09-15T12:17:22+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/105678.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/105678.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/105678.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ \u57fa\u7840\u5165\u95e8\u7bc7\uff08\u4e09\uff09\uff1a\u5185\u8054\u51fd\u6570\u4e0e\u7a7a\u6307\u9488\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++ \u57fa\u7840\u5165\u95e8\u7bc7\uff08\u4e09\uff09\uff1a\u5185\u8054\u51fd\u6570\u4e0e\u7a7a\u6307\u9488 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/105678.html","og_locale":"zh_CN","og_type":"article","og_title":"C++ \u57fa\u7840\u5165\u95e8\u7bc7\uff08\u4e09\uff09\uff1a\u5185\u8054\u51fd\u6570\u4e0e\u7a7a\u6307\u9488 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u76ee\u5f55\u4e00. \u5185\u8054\u51fd\u65701.1 \u5185\u8054\u51fd\u6570\u7684\u5b9a\u4e491.2 \u5b8f\u51fd\u6570\u7684\u7f3a\u9677\u4e0e\u95ee\u98981.3 \u5185\u8054\u51fd\u6570\u7684\u4f7f\u75281.4 \u5185\u8054\u51fd\u6570\u7684\u5e95\u5c42\u7ec6\u82821.5 \u5185\u8054\u51fd\u6570\u7684\u4f18\u7f3a\u70b91.5.1 \u5185\u8054\u5c55\u5f00\u7684\u95ee\u98981.5.2 \u58f0\u660e\u4e0e\u5b9a\u4e49\u5206\u79bb\u4e8c. nullptr&#xff08;c11\u65b0\u589e\u5185\u5bb9&#xff09;2.1 \u4e3a\u4ec0\u4e48\u9700\u8981 nullptr ?2.2 nullptr \u662f\u4ec0\u4e48 ?2.3 \u91cd\u8f7d\u89e3\u6790\u4e2d\u7684\u8868\u73b0\u4e00. \u5185\u8054\u51fd\u6570 1.1 \u5185\u8054\u51fd\u6570\u7684\u5b9a\u4e49 \u7528 inline \u4fee\u9970\u7684\u51fd\u6570\u53eb\u505a\u5185\u8054\u51fd\u6570&#xff0c;\u7f16\u8bd1\u65f6 C \u7f16\u8bd1\u5668\u4f1a\u5728\u8c03","og_url":"https:\/\/www.wsisp.com\/helps\/105678.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-15T12:17:22+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/09\/20260915121719-6aa9374fbd7cf.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/105678.html","url":"https:\/\/www.wsisp.com\/helps\/105678.html","name":"C++ \u57fa\u7840\u5165\u95e8\u7bc7\uff08\u4e09\uff09\uff1a\u5185\u8054\u51fd\u6570\u4e0e\u7a7a\u6307\u9488 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-15T12:17:22+00:00","dateModified":"2026-09-15T12:17:22+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/105678.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/105678.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/105678.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C++ \u57fa\u7840\u5165\u95e8\u7bc7\uff08\u4e09\uff09\uff1a\u5185\u8054\u51fd\u6570\u4e0e\u7a7a\u6307\u9488"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/105678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=105678"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/105678\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/105674"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=105678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=105678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=105678"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=105678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}