{"id":97353,"date":"2026-08-29T09:48:45","date_gmt":"2026-08-29T01:48:45","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/97353.html"},"modified":"2026-08-29T09:48:45","modified_gmt":"2026-08-29T01:48:45","slug":"c%e7%b1%bb%e5%92%8c%e5%af%b9%e8%b1%a1%ef%bc%88%e4%b8%8a%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/97353.html","title":{"rendered":"c++\u7c7b\u548c\u5bf9\u8c61\uff08\u4e0a\uff09"},"content":{"rendered":"<h2>\u7c7b\u7684\u5b9a\u4e49<\/h2>\n<ul>\n<li>class\u4e3a\u7c7b\u7684\u5173\u952e\u5b57&#xff0c;\u6ce8\u610f\u7c7b\u5b9a\u4e49\u7ed3\u675f\u65f6\u540e\u2faf\u5206\u53f7\u4e0d\u80fd\u7701\u7565\u3002<\/li>\n<li>\u4e3a\u4e86\u533a\u5206\u6210\u5458\u53d8\u91cf&#xff0c;\u2f00\u822c\u4e60\u60ef\u4e0a\u6210\u5458\u53d8\u91cf\u4f1a\u52a0\u2f00\u4e2a\u7279\u6b8a\u6807\u8bc6&#xff0c;\u5982\u6210\u5458\u53d8\u91cf\u524d\u2faf\u6216\u8005\u540e\u2faf\u52a0_\u6216\u8005m \u5f00\u5934&#xff0c;\u6ce8\u610fC&#043;&#043;\u4e2d\u8fd9\u4e2a\u5e76\u4e0d\u662f\u5f3a\u5236\u7684&#xff0c;\u53ea\u662f\u2f00\u4e9b\u60ef\u4f8b&#xff0c;\u5177\u4f53\u770b\u516c\u53f8\u7684\u8981\u6c42\u3002<\/li>\n<li>C&#043;&#043;\u4e2dstruct\u4e5f\u53ef\u4ee5\u5b9a\u4e49\u7c7b&#xff0c;C&#043;&#043;\u517c\u5bb9C\u4e2dstruct\u7684\u2f64\u6cd5&#xff0c;\u540c\u65f6struct\u5347\u7ea7\u6210\u4e86\u7c7b&#xff0c;\u660e\u663e\u7684\u53d8\u5316\u662f struct\u4e2d\u53ef\u4ee5\u5b9a\u4e49\u51fd\u6570&#xff0c;\u2f00\u822c\u60c5\u51b5\u4e0b\u6211\u4eec\u8fd8\u662f\u63a8\u8350\u2f64class\u5b9a\u4e49\u7c7b<\/li>\n<li>\u5b9a\u4e49\u5728\u7c7b\u2faf\u7684\u6210\u5458\u51fd\u6570\u9ed8\u8ba4\u4e3ainline<\/li>\n<\/ul>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Student<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token keyword\">public<\/span><span class=\"token operator\">:<\/span><br \/>\n<span class=\"token comment\">\/\/ \u6784\u9020\u51fd\u6570&#xff1a;\u4f7f\u7528\u521d\u59cb\u5316\u5217\u8868\u7ed9\u6210\u5458\u8d4b\u503c<\/span><br \/>\n<span class=\"token function\">Student<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">const<\/span> string<span class=\"token operator\">&amp;<\/span> name<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> age<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">double<\/span> height<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> classId<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token operator\">:<\/span> <span class=\"token function\">_name<\/span><span class=\"token punctuation\">(<\/span>name<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">_age<\/span><span class=\"token punctuation\">(<\/span>age<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">_height<\/span><span class=\"token punctuation\">(<\/span>height<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token function\">_classId<\/span><span class=\"token punctuation\">(<\/span>classId<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/\u6210\u5458\u51fd\u6570<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">Hello<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">const<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;\u59d3\u540d: &#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> _name <span class=\"token operator\">&lt;&lt;<\/span> endl<span class=\"token punctuation\">;<\/span><br \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;\u5e74\u9f84: &#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> _age <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034; \u5c81&#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> endl<span class=\"token punctuation\">;<\/span><br \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;\u8eab\u9ad8: &#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> _height <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034; \u7c73&#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> endl<span class=\"token punctuation\">;<\/span><br \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;\u73ed\u7ea7: &#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> _classId <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034; \u73ed&#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> endl<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">private<\/span><span class=\"token operator\">:<\/span><br \/>\n<span class=\"token comment\">\/\/\u6210\u5458\u53d8\u91cf<\/span><br \/>\nstring _name<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> _age<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">double<\/span> _height<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> _classId<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\nStudent <span class=\"token function\">stu<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u5f20\u4e09&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">18<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1.75<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2024<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nstu<span class=\"token punctuation\">.<\/span><span class=\"token function\">Hello<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h3>\u8bbf\u95ee\u9650\u5b9a\u7b26<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260829014843-6a923a7b94cd4.png\" alt=\"\u8bbf\u95ee\u9650\u5b9a\u7b26\" \/><\/p>\n<ul>\n<li>class\u5b9a\u4e49\u6210\u5458\u6ca1\u6709\u88ab\u8bbf\u95ee\u9650\u5b9a\u7b26\u4fee\u9970\u65f6\u9ed8\u8ba4\u4e3aprivate&#xff0c;struct\u9ed8\u8ba4\u4e3apublic<\/li>\n<li>public\u4fee\u9970\u7684\u6210\u5458\u5728\u7c7b\u5916\u53ef\u4ee5\u76f4\u63a5\u88ab\u8bbf\u95ee&#xff1b;protected\u548cprivate\u4fee\u9970\u7684\u6210\u5458\u5728\u7c7b\u5916\u4e0d\u80fd\u76f4\u63a5\u88ab\u8bbf \u95ee&#xff0c;protected\u548cprivate\u662f\u2f00\u6837\u7684<\/li>\n<li>\u8bbf\u95ee\u6743\u9650\u4f5c\u2f64\u57df\u4ece\u8be5\u8bbf\u95ee\u9650\u5b9a\u7b26\u51fa\u73b0\u7684\u4f4d\u7f6e\u5f00\u59cb\u76f4\u5230\u4e0b\u2f00\u4e2a\u8bbf\u95ee\u9650\u5b9a\u7b26\u51fa\u73b0\u65f6\u4e3a\u2f4c&#xff0c;\u5982\u679c\u540e\u2faf\u6ca1\u6709 \u8bbf\u95ee\u9650\u5b9a\u7b26&#xff0c;\u4f5c\u2f64\u57df\u5c31\u5230}\u5373\u7c7b\u7ed3\u675f\u3002<\/li>\n<\/ul>\n<h3>\u7c7b\u57df<\/h3>\n<ul>\n<li>\u7c7b\u57df\u5f71\u54cd\u7684\u662f\u7f16\u8bd1\u7684\u67e5\u627e\u89c4\u5219&#xff0c;\u4e0b\u2faf\u7a0b\u5e8f\u4e2dInit\u5982\u679c\u4e0d\u6307\u5b9a\u7c7b\u57dfStack&#xff0c;\u90a3\u4e48\u7f16\u8bd1\u5668\u5c31\u628aInit\u5f53\u6210\u5168 \u5c40\u51fd\u6570&#xff0c;\u90a3\u4e48\u7f16\u8bd1\u65f6&#xff0c;\u627e\u4e0d\u5230array\u7b49\u6210\u5458\u7684\u58f0\u660e\/\u5b9a\u4e49\u5728\u54ea\u2fa5&#xff0c;\u5c31\u4f1a\u62a5\u9519\u3002\u6307\u5b9a\u7c7b\u57dfStack&#xff0c;\u5c31\u662f\u77e5 \u9053Init\u662f\u6210\u5458\u51fd\u6570&#xff0c;\u5f53\u524d\u57df\u627e\u4e0d\u5230\u7684array\u7b49\u6210\u5458&#xff0c;\u5c31\u4f1a\u5230\u7c7b\u57df\u4e2d\u53bb\u67e5\u627e\u3002<\/li>\n<\/ul>\n<p><span class=\"token comment\">\/\/ \u58f0\u660e\u548c\u5b9a\u4e49\u5206\u79bb&#xff0c;\u9700\u8981\u6307\u5b9a\u7c7b\u57df<\/span><\/p>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token class-name\">Stack<\/span><span class=\"token double-colon punctuation\">::<\/span><span class=\"token function\">Init<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> n<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\narray <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><span class=\"token function\">malloc<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">*<\/span> n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">nullptr<\/span> <span class=\"token operator\">&#061;&#061;<\/span> array<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token function\">perror<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;malloc\u7533\u8bf7\u7a7a\u95f4\u5931\u8d25&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">return<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\ncapacity <span class=\"token operator\">&#061;<\/span> n<span class=\"token punctuation\">;<\/span><br \/>\ntop <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h2>\u5b9e\u4f8b\u5316<\/h2>\n<p>\u7c7b\u7684\u5b9a\u4e49\u5b9e\u73b0\u4e86\u4e00\u4e2a\u6a21\u677f&#xff0c;\u4f46\u662f\u8981\u4f7f\u7528\u5c31\u9700\u8981\u7528\u7c7b\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61<\/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;iostream&gt;<\/span><\/span><br \/>\n<span class=\"token keyword\">using<\/span> <span class=\"token keyword\">namespace<\/span> std<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Date<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token keyword\">public<\/span><span class=\"token operator\">:<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">Init<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> year<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> month<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> day<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n_year <span class=\"token operator\">&#061;<\/span> year<span class=\"token punctuation\">;<\/span><br \/>\n_month <span class=\"token operator\">&#061;<\/span> month<span class=\"token punctuation\">;<\/span><br \/>\n_day <span class=\"token operator\">&#061;<\/span> day<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">Print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> _year <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;\/&#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> _month <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token string\">&#034;\/&#034;<\/span> <span class=\"token operator\">&lt;&lt;<\/span> _day <span class=\"token operator\">&lt;&lt;<\/span> endl<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token keyword\">private<\/span><span class=\"token operator\">:<\/span><br \/>\n<span class=\"token comment\">\/\/ \u8fd9\u2fa5\u53ea\u662f\u58f0\u660e&#xff0c;\u6ca1\u6709\u5f00\u7a7a\u95f4<\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> _year<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> _month<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> _day<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token comment\">\/\/ Date\u7c7b\u5b9e\u4f8b\u5316\u51fa\u5bf9\u8c61d1\u548cd2 <\/span><br \/>\nDate d1<span class=\"token punctuation\">;<\/span><br \/>\nDate d2<span class=\"token punctuation\">;<\/span><br \/>\nd1<span class=\"token punctuation\">.<\/span><span class=\"token function\">Init<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">2024<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">31<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nd1<span class=\"token punctuation\">.<\/span><span class=\"token function\">Print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nd2<span class=\"token punctuation\">.<\/span><span class=\"token function\">Init<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">2024<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">7<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nd2<span class=\"token punctuation\">.<\/span><span class=\"token function\">Print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h2>\u7c7b\u7684\u5927\u5c0f<\/h2>\n<p>\u5206\u6790\u2f00\u4e0b\u7c7b\u5bf9\u8c61\u4e2d\u54ea\u4e9b\u6210\u5458\u5462&#xff1f;\u7c7b\u5b9e\u4f8b\u5316\u51fa\u7684\u6bcf\u4e2a\u5bf9\u8c61&#xff0c;\u90fd\u6709\u72ec\u2f74\u7684\u6570\u636e\u7a7a\u95f4&#xff0c;\u6240\u4ee5\u5bf9\u8c61\u4e2d\u80af\u5b9a\u5305\u542b\u6210\u5458\u53d8\u91cf&#xff0c;\u90a3\u4e48\u6210\u5458\u51fd\u6570\u662f\u5426\u5305\u542b\u5462&#xff1f;\u2fb8\u5148\u51fd\u6570\u88ab\u7f16\u8bd1\u540e\u662f\u2f00\u6bb5\u6307\u4ee4&#xff0c;\u5bf9\u8c61\u4e2d\u6ca1\u529e\u6cd5\u5b58\u50a8&#xff0c;\u8fd9\u4e9b\u6307\u4ee4\u5b58\u50a8\u5728\u2f00\u4e2a\u5355\u72ec\u7684\u533a\u57df(\u4ee3\u7801\u6bb5)&#xff0c;\u90a3\u4e48\u5bf9\u8c61\u4e2d\u2fae\u8981\u5b58\u50a8\u7684\u8bdd&#xff0c;\u53ea\u80fd\u662f\u6210\u5458\u51fd\u6570\u7684\u6307\u9488\u3002\u518d\u5206\u6790\u2f00\u4e0b&#xff0c;\u5bf9\u8c61\u4e2d\u662f\u5426\u6709\u5b58\u50a8\u6307\u9488\u7684\u5fc5\u8981\u5462&#xff0c;Date\u5b9e\u4f8b\u5316d1\u548cd2\u4e24\u4e2a\u5bf9\u8c61&#xff0c;d1\u548cd2\u90fd\u6709\u5404\u2f83\u72ec\u2f74\u7684\u6210\u5458\u53d8\u91cf_year\/_month\/_day\u5b58\u50a8\u5404\u2f83\u7684\u6570\u636e&#xff0c;\u4f46\u662fd1\u548cd2\u7684\u6210\u5458\u51fd\u6570Init\/Print\u6307\u9488\u5374\u662f\u2f00\u6837\u7684&#xff0c;\u5b58\u50a8\u5728\u5bf9\u8c61\u4e2d\u5c31\u6d6a\u8d39\u4e86\u3002\u5982\u679c\u2f64Date\u5b9e\u4f8b\u5316100\u4e2a\u5bf9\u8c61&#xff0c;\u90a3\u4e48\u6210\u5458\u51fd\u6570\u6307\u9488\u5c31\u91cd\u590d\u5b58\u50a8100\u6b21&#xff0c;\u592a\u6d6a\u8d39\u4e86\u3002\u8fd9\u2fa5\u9700\u8981\u518d\u989d\u5916\u54c6\u55e6\u2f00\u4e0b&#xff0c;\u5176\u5b9e\u51fd\u6570\u6307\u9488\u662f\u4e0d\u9700\u8981\u5b58\u50a8\u7684&#xff0c;\u51fd\u6570\u6307\u9488\u662f\u2f00\u4e2a\u5730\u5740&#xff0c;\u8c03\u2f64\u51fd\u6570\u88ab\u7f16\u8bd1\u6210\u6c47\u7f16\u6307\u4ee4[call \u5730\u5740]&#xff0c;\u5176\u5b9e\u7f16\u8bd1\u5668\u5728\u7f16\u8bd1\u94fe\u63a5\u65f6&#xff0c;\u5c31\u8981\u627e\u5230\u51fd\u6570\u7684\u5730\u5740&#xff0c;\u4e0d\u662f\u5728\u8fd0\u2f8f\u65f6\u627e&#xff0c;\u53ea\u6709\u52a8\u6001\u591a\u6001\u662f\u5728\u8fd0\u2f8f\u65f6\u627e&#xff0c;\u5c31\u9700\u8981\u5b58\u50a8\u51fd\u6570\u5730\u5740 \u5185\u5b58\u5bf9\u9f50\u89c4\u5219<\/p>\n<ul>\n<li>\u7b2c\u2f00\u4e2a\u6210\u5458\u5728\u4e0e\u7ed3\u6784\u4f53\u504f\u79fb\u91cf\u4e3a0\u7684\u5730\u5740\u5904<\/li>\n<li>\u5176\u4ed6\u6210\u5458\u53d8\u91cf\u8981\u5bf9\u2eec\u5230\u67d0\u4e2a\u6570\u5b57&#xff08;\u5bf9\u2eec\u6570&#xff09;\u7684\u6574\u6570\u500d\u7684\u5730\u5740\u5904<\/li>\n<li>\u6ce8\u610f&#xff1a;\u5bf9\u2eec\u6570&#061;\u7f16\u8bd1\u5668\u9ed8\u8ba4\u7684\u2f00\u4e2a\u5bf9\u2eec\u6570\u4e0e\u8be5\u6210\u5458\u2f24\u2f29\u7684\u8f83\u2f29\u503c<\/li>\n<li>VS\u4e2d\u9ed8\u8ba4\u7684\u5bf9\u2eec\u6570\u4e3a8<\/li>\n<li>\u7ed3\u6784\u4f53\u603b\u2f24\u2f29\u4e3a&#xff1a;\u6700\u2f24\u5bf9\u2eec\u6570&#xff08;\u6240\u6709\u53d8\u91cf\u7c7b\u578b\u6700\u2f24\u8005\u4e0e\u9ed8\u8ba4\u5bf9\u2eec\u53c2\u6570\u53d6\u6700\u2f29&#xff09;\u7684\u6574\u6570\u500d<\/li>\n<li>\u5982\u679c\u5d4c\u5957\u4e86\u7ed3\u6784\u4f53\u7684\u60c5\u51b5&#xff0c;\u5d4c\u5957\u7684\u7ed3\u6784\u4f53\u5bf9\u2eec\u5230\u2f83\u2f30\u7684\u6700\u2f24\u5bf9\u2eec\u6570\u7684\u6574\u6570\u500d\u5904&#xff0c;\u7ed3\u6784\u4f53\u7684\u6574\u4f53\u2f24\u2f29 \u5c31\u662f\u6240\u6709\u6700\u2f24\u5bf9\u2eec\u6570&#xff08;\u542b\u5d4c\u5957\u7ed3\u6784\u4f53\u7684\u5bf9\u2eec\u6570&#xff09;\u7684\u6574\u6570\u500d<\/li>\n<\/ul>\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;iostream&gt;<\/span><\/span><br \/>\n<span class=\"token keyword\">using<\/span> <span class=\"token keyword\">namespace<\/span> std<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ \u8ba1\u7b97\u2f00\u4e0bA\/B\/C\u5b9e\u4f8b\u5316\u7684\u5bf9\u8c61\u662f\u591a\u2f24&#xff1f;<\/span><\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">A<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token keyword\">public<\/span><span class=\"token operator\">:<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">Print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> _ch <span class=\"token operator\">&lt;&lt;<\/span> endl<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token keyword\">private<\/span><span class=\"token operator\">:<\/span><br \/>\n<span class=\"token keyword\">char<\/span> _ch<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> _i<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">class<\/span> <span class=\"token class-name\">B<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token keyword\">public<\/span><span class=\"token operator\">:<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">Print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token comment\">\/\/&#8230;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">class<\/span> <span class=\"token class-name\">C<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\nA a<span class=\"token punctuation\">;<\/span><br \/>\nB b<span class=\"token punctuation\">;<\/span><br \/>\nC c<span class=\"token punctuation\">;<\/span><br \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;&lt;<\/span> endl<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/8<\/span><br \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span>b<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;&lt;<\/span> endl<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/1<\/span><br \/>\ncout <span class=\"token operator\">&lt;&lt;<\/span> <span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span>c<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;&lt;<\/span> endl<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/1<\/span><br \/>\n<span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u4e0a\u2faf\u7684\u7a0b\u5e8f\u8fd0\u2f8f\u540e&#xff0c;\u6211\u4eec\u770b\u5230\u6ca1\u6709\u6210\u5458\u53d8\u91cf\u7684B\u548cC\u7c7b\u5bf9\u8c61\u7684\u2f24\u2f29\u662f1&#xff0c;\u4e3a\u4ec0\u4e48\u6ca1\u6709\u6210\u5458\u53d8\u91cf\u8fd8\u8981\u7ed91\u4e2a\u5b57\u8282\u5462&#xff1f;\u56e0\u4e3a\u5982\u679c\u2f00\u4e2a\u5b57\u8282\u90fd\u4e0d\u7ed9&#xff0c;\u600e\u4e48\u8868\u2f70\u5bf9\u8c61\u5b58\u5728\u8fc7\u5462&#xff01;\u6240\u4ee5\u8fd9\u2fa5\u7ed91\u5b57\u8282&#xff0c;\u7eaf\u7cb9\u662f\u4e3a\u4e86\u5360\u4f4d\u6807\u8bc6\u5bf9\u8c61\u5b58\u5728<\/p>\n<h2>this\u6307\u9488<\/h2>\n<ul>\n<li>Date\u7c7b\u4e2d\u6709Init\u4e0ePrint\u4e24\u4e2a\u6210\u5458\u51fd\u6570&#xff0c;\u51fd\u6570\u4f53\u4e2d\u6ca1\u6709\u5173\u4e8e\u4e0d\u540c\u5bf9\u8c61\u7684\u533a\u5206&#xff0c;\u90a3\u5f53d1\u8c03\u2f64Init\u548c Print\u51fd\u6570\u65f6&#xff0c;\u8be5\u51fd\u6570\u662f\u5982\u4f55\u77e5\u9053\u5e94\u8be5\u8bbf\u95ee\u7684\u662fd1\u5bf9\u8c61\u8fd8\u662fd2\u5bf9\u8c61\u5462&#xff1f;\u90a3\u4e48\u8fd9\u2fa5\u5c31\u8981\u770b\u5230C&#043;&#043;\u7ed9\u4e86 \u2f00\u4e2a\u9690\u542b\u7684this\u6307\u9488\u89e3\u51b3\u8fd9\u2fa5\u7684\u95ee\u9898<\/li>\n<li>\u7f16\u8bd1\u5668\u7f16\u8bd1\u540e&#xff0c;\u7c7b\u7684\u6210\u5458\u51fd\u6570\u9ed8\u8ba4\u90fd\u4f1a\u5728\u5f62\u53c2\u7b2c\u2f00\u4e2a\u4f4d\u7f6e&#xff0c;\u589e\u52a0\u2f00\u4e2a\u5f53\u524d\u7c7b\u7c7b\u578b\u7684\u6307\u9488&#xff0c;\u53eb\u505athis \u6307\u9488\u3002\u2f50\u5982Date\u7c7b\u7684Init\u7684\u771f\u5b9e\u539f\u578b\u4e3a&#xff0c;void Init(Date* const this, int year, int month, int day)<\/li>\n<li>\u7c7b\u7684\u6210\u5458\u51fd\u6570\u4e2d\u8bbf\u95ee\u6210\u5458\u53d8\u91cf&#xff0c;\u672c\u8d28\u90fd\u662f\u901a\u8fc7this\u6307\u9488\u8bbf\u95ee\u7684&#xff0c;\u5982Init\u51fd\u6570\u4e2d\u7ed9_year\u8d4b\u503c&#xff0c;this-&gt;_year &#061; year;<\/li>\n<li>C&#043;&#043;\u89c4\u5b9a\u4e0d\u80fd\u5728\u5b9e\u53c2\u548c\u5f62\u53c2\u7684\u4f4d\u7f6e\u663e\u2f70\u7684\u5199this\u6307\u9488(\u7f16\u8bd1\u65f6\u7f16\u8bd1\u5668\u4f1a\u5904\u7406)&#xff0c;\u4f46\u662f\u53ef\u4ee5\u5728\u51fd\u6570\u4f53\u5185\u663e \u2f70\u4f7f\u2f64this\u6307\u9488<\/li>\n<\/ul>\n<p>c&#043;&#043;this\u6307\u9488\u5b58\u5728\u5728\u5185\u5b58\u7684\u54ea\u91cc? \u5173\u4e8e this \u6307\u9488\u5728\u5185\u5b58\u4e2d\u7684\u4f4d\u7f6e&#xff0c;\u6838\u5fc3\u7ed3\u8bba\u662f&#xff1a;\u5b83\u6ca1\u6709\u56fa\u5b9a\u7684\u5b58\u50a8\u4f4d\u7f6e&#xff0c;\u5b8c\u5168\u53d6\u51b3\u4e8e\u7f16\u8bd1\u5668\u5b9e\u73b0\u548c\u8c03\u7528\u7ea6\u5b9a\u3002<\/p>\n<p>\u4f46\u53ef\u4ee5\u660e\u786e\u7684\u662f&#xff1a;this \u6307\u9488\u672c\u8eab\u7edd\u4e0d\u5b58\u50a8\u5728\u5bf9\u8c61\u7684\u5185\u5b58\u7a7a\u95f4\u4e2d&#xff08;\u5bf9\u8c61\u91cc\u53ea\u5b58\u6210\u5458\u53d8\u91cf&#xff09;\u3002\u5b83\u672c\u8d28\u4e0a\u662f\u975e\u9759\u6001\u6210\u5458\u51fd\u6570\u7684\u4e00\u4e2a\u9690\u5f0f\u5f62\u53c2\u3002<\/p>\n<p>\u6839\u636e\u4e0d\u540c\u7684\u7f16\u8bd1\u4f18\u5316\u7ea7\u522b\u548c\u786c\u4ef6\u5e73\u53f0&#xff0c;\u5b83\u7684\u5b9e\u9645\u6816\u8eab\u4e4b\u6240\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u79cd\u60c5\u51b5&#xff1a;<\/p>\n<p>1. \u5bc4\u5b58\u5668&#xff08;\u7edd\u5927\u591a\u6570\u9ad8\u6027\u80fd\u573a\u666f&#xff09; \u5728 x86-64 \u67b6\u6784\u4e0b&#xff0c;\u7f16\u8bd1\u5668\u4f1a\u4f18\u5148\u4f7f\u7528\u5bc4\u5b58\u5668\u4f20\u9012 this&#xff1a;<\/p>\n<ul>\n<li>Windows&#xff08;x64 \u8c03\u7528\u7ea6\u5b9a&#xff09;&#xff1a;this \u4fdd\u5b58\u5728 RCX \u5bc4\u5b58\u5668\u4e2d\u3002<\/li>\n<li>Linux \/ macOS&#xff08;System V ABI&#xff09;&#xff1a;this \u4fdd\u5b58\u5728 RDI \u5bc4\u5b58\u5668\u4e2d\u3002<\/li>\n<li>ARM \u67b6\u6784&#xff1a;\u901a\u5e38\u4fdd\u5b58\u5728 R0&#xff08;\u7b2c\u4e00\u4e2a\u901a\u7528\u5bc4\u5b58\u5668&#xff09;\u4e2d\u3002 \u53ea\u8981\u51fd\u6570\u4f53\u4e0d\u590d\u6742&#xff0c;\u7f16\u8bd1\u5668\u4f1a\u4e00\u76f4\u901a\u8fc7\u5bc4\u5b58\u5668\u8bbf\u95ee this&#xff0c;\u6b64\u65f6\u5b83\u4e0d\u5b58\u5728\u4e8e\u5185\u5b58\u4e2d&#xff0c;\u53ea\u5728 CPU \u5185\u90e8\u6d41\u8f6c\u3002<\/li>\n<\/ul>\n<p>2. \u6808\u5185\u5b58&#xff08;\u5bc4\u5b58\u5668\u6ea2\u51fa\u6216\u88ab\u53d6\u5730\u5740\u65f6&#xff09; \u5f53\u51fd\u6570\u903b\u8f91\u590d\u6742&#xff0c;\u5bc4\u5b58\u5668\u4e0d\u591f\u7528\u65f6&#xff0c;\u7f16\u8bd1\u5668\u4f1a\u628a this \u7684\u503c\u4ece\u5bc4\u5b58\u5668\u201c\u6ea2\u51fa\u201d\u5230**\u5f53\u524d\u51fd\u6570\u7684\u6808\u5e27&#xff08;Stack Frame&#xff09;**\u4e2d&#xff0c;\u4fdd\u5b58\u4e3a\u4e00\u4e2a\u5c40\u90e8\u4e34\u65f6\u53d8\u91cf\u3002\u6b64\u5916&#xff0c;\u5728 x86&#xff08;32\u4f4d&#xff09;\u4f20\u7edf\u7684 thiscall \u8c03\u7528\u7ea6\u5b9a\u4e0b&#xff0c;this \u4f1a\u88ab\u76f4\u63a5\u538b\u5165\u8c03\u7528\u6808\u4e2d&#xff0c;\u4f5c\u4e3a\u51fd\u6570\u53c2\u6570\u4f20\u9012\u3002<\/p>\n<p>3. \u5168\u5c40\/\u9759\u6001\u5b58\u50a8\u533a&#xff08;\u6781\u7279\u6b8a\u60c5\u51b5&#xff09; \u5982\u679c\u5bf9\u8c61\u662f\u5168\u5c40\u5bf9\u8c61\u6216\u9759\u6001\u5c40\u90e8\u5bf9\u8c61&#xff0c;this \u6307\u9488\u7684\u503c&#xff08;\u5373\u5730\u5740&#xff09;\u6307\u5411\u5168\u5c40\/\u9759\u6001\u5b58\u50a8\u533a\u3002\u4f46\u8bf7\u6ce8\u610f&#xff0c;\u8fd9\u6307\u7684\u662f this \u6307\u5411\u7684\u5185\u5bb9\u5728\u90a3\u91cc&#xff0c;\u800c this \u6307\u9488\u53d8\u91cf\u672c\u8eab&#xff08;\u82e5\u88ab\u5b58\u5230\u5185\u5b58\u91cc&#xff09;\u4f9d\u7136\u5728\u51fd\u6570\u7684\u6808\u5e27\u6216\u5bc4\u5b58\u5668\u4e2d\u3002<\/p>\n<p>4. Lambda \u6355\u83b7\u5668\u5185\u90e8 \u5982\u679c Lambda \u8868\u8fbe\u5f0f\u6355\u83b7\u4e86 this&#xff08;[this] \u6216 [&#061;]&#xff09;&#xff0c;\u90a3\u4e48\u8fd9\u4e2a this \u6307\u9488\u7684\u503c\u4f1a\u88ab\u5b58\u50a8\u5728 Lambda \u95ed\u5305\u5bf9\u8c61&#xff08;Closure&#xff09; \u7684\u5185\u5b58\u4e2d\u3002\u5982\u679c\u8fd9\u4e2a Lambda \u662f\u5c40\u90e8\u53d8\u91cf&#xff0c;\u95ed\u5305\u5c31\u5728\u6808\u4e0a&#xff1b;\u5982\u679c\u88ab new \u51fa\u6765&#xff0c;\u5c31\u5728\u5806\u4e0a\u3002<\/p>\n<hr \/>\n<p>\u8865\u5145\u4e24\u4e2a\u5bb9\u6613\u6df7\u6dc6\u7684\u51b7\u77e5\u8bc6&#xff1a;<\/p>\n<ul>\n<li>this \u662f\u53f3\u503c&#xff1a;C&#043;&#043; \u6807\u51c6\u89c4\u5b9a this \u662f\u4e00\u4e2a\u7eaf\u53f3\u503c&#xff08;prvalue&#xff09;&#xff0c;\u4f60\u4e0d\u80fd\u5bf9 this \u53d6\u5730\u5740&#xff08;&amp;this \u662f\u7f16\u8bd1\u9519\u8bef&#xff09;&#xff0c;\u6240\u4ee5\u4e0d\u5b58\u5728\u201cthis \u6307\u9488\u7684\u5730\u5740\u201d\u8fd9\u4e00\u8bf4\u6cd5&#xff0c;\u53ea\u6709\u201cthis \u6307\u5411\u7684\u5bf9\u8c61\u7684\u5730\u5740\u201d\u3002<\/li>\n<li>\u865a\u51fd\u6570\u8868&#xff08;vptr&#xff09;&#xff1a;\u867d\u7136 this \u4e0d\u5728\u5bf9\u8c61\u91cc&#xff0c;\u4f46\u5bf9\u8c61\u5185\u5b58\u5e03\u5c40\u7684\u6700\u524d\u9762\u901a\u5e38\u6709\u4e00\u4e2a\u6307\u5411\u865a\u51fd\u6570\u8868&#xff08;vtable&#xff09;\u7684\u6307\u9488&#xff08;vptr&#xff09;\u3002\u5f53\u8c03\u7528\u865a\u51fd\u6570\u65f6&#xff0c;\u7f16\u8bd1\u5668\u4f1a\u901a\u8fc7 this \u627e\u5230\u8fd9\u4e2a vptr&#xff0c;\u518d\u627e\u5230\u771f\u6b63\u7684\u51fd\u6570\u5730\u5740\u3002<\/li>\n<\/ul>\n<p>\u603b\u7ed3\u4e00\u53e5\u8bdd&#xff1a;\u5e73\u65f6\u8fd0\u884c\u4e2d\u5b83\u4f18\u5148\u5f85\u5728\u5bc4\u5b58\u5668\u91cc&#xff0c;\u9700\u8981\u4fdd\u5b58\u65f6\u624d\u4e34\u65f6\u653e\u5728\u6808\u4e0a&#xff0c;\u4f46\u6c38\u8fdc\u4e0d\u5c5e\u4e8e\u5bf9\u8c61\u672c\u8eab\u3002 \u5f00\u53d1\u65f6\u65e0\u9700\u5173\u5fc3\u5b83\u7684\u7269\u7406\u4f4d\u7f6e&#xff0c;\u4ea4\u7ed9\u7f16\u8bd1\u5668\u4f18\u5316\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7c7b\u7684\u5b9a\u4e49<br \/>\nclass\u4e3a\u7c7b\u7684\u5173\u952e\u5b57&#xff0c;\u6ce8\u610f\u7c7b\u5b9a\u4e49\u7ed3\u675f\u65f6\u540e\u2faf\u5206\u53f7\u4e0d\u80fd\u7701\u7565\u3002\u4e3a\u4e86\u533a\u5206\u6210\u5458\u53d8\u91cf&#xff0c;\u2f00\u822c\u4e60\u60ef\u4e0a\u6210\u5458\u53d8\u91cf\u4f1a\u52a0\u2f00\u4e2a\u7279\u6b8a\u6807\u8bc6&#xff0c;\u5982\u6210\u5458\u53d8\u91cf\u524d\u2faf\u6216\u8005\u540e\u2faf\u52a0_\u6216\u8005m \u5f00\u5934&#xff0c;\u6ce8\u610fC\u4e2d\u8fd9\u4e2a\u5e76\u4e0d\u662f\u5f3a\u5236\u7684&#xff0c;\u53ea\u662f\u2f00\u4e9b\u60ef\u4f8b&#xff0c;\u5177\u4f53\u770b\u516c\u53f8\u7684\u8981\u6c42\u3002C\u4e2dstruct\u4e5f\u53ef\u4ee5\u5b9a\u4e49\u7c7b&#xff0c;C\u517c\u5bb9C\u4e2dstruct\u7684\u2f64\u6cd5&#xff0c;\u540c\u65f6struct\u5347\u7ea7\u6210\u4e86\u7c7b&#xff0c;\u660e\u663e\u7684\u53d8\u5316\u662f struct\u4e2d\u53ef\u4ee5\u5b9a\u4e49\u51fd\u6570&amp;#<\/p>\n","protected":false},"author":2,"featured_media":97352,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,190],"topic":[],"class_list":["post-97353","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-c","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>c++\u7c7b\u548c\u5bf9\u8c61\uff08\u4e0a\uff09 - \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\/97353.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"c++\u7c7b\u548c\u5bf9\u8c61\uff08\u4e0a\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u7c7b\u7684\u5b9a\u4e49 class\u4e3a\u7c7b\u7684\u5173\u952e\u5b57&#xff0c;\u6ce8\u610f\u7c7b\u5b9a\u4e49\u7ed3\u675f\u65f6\u540e\u2faf\u5206\u53f7\u4e0d\u80fd\u7701\u7565\u3002\u4e3a\u4e86\u533a\u5206\u6210\u5458\u53d8\u91cf&#xff0c;\u2f00\u822c\u4e60\u60ef\u4e0a\u6210\u5458\u53d8\u91cf\u4f1a\u52a0\u2f00\u4e2a\u7279\u6b8a\u6807\u8bc6&#xff0c;\u5982\u6210\u5458\u53d8\u91cf\u524d\u2faf\u6216\u8005\u540e\u2faf\u52a0_\u6216\u8005m \u5f00\u5934&#xff0c;\u6ce8\u610fC\u4e2d\u8fd9\u4e2a\u5e76\u4e0d\u662f\u5f3a\u5236\u7684&#xff0c;\u53ea\u662f\u2f00\u4e9b\u60ef\u4f8b&#xff0c;\u5177\u4f53\u770b\u516c\u53f8\u7684\u8981\u6c42\u3002C\u4e2dstruct\u4e5f\u53ef\u4ee5\u5b9a\u4e49\u7c7b&#xff0c;C\u517c\u5bb9C\u4e2dstruct\u7684\u2f64\u6cd5&#xff0c;\u540c\u65f6struct\u5347\u7ea7\u6210\u4e86\u7c7b&#xff0c;\u660e\u663e\u7684\u53d8\u5316\u662f struct\u4e2d\u53ef\u4ee5\u5b9a\u4e49\u51fd\u6570&amp;#\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/97353.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-29T01:48:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260829014843-6a923a7b94cd4.png\" \/>\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\/97353.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/97353.html\",\"name\":\"c++\u7c7b\u548c\u5bf9\u8c61\uff08\u4e0a\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-29T01:48:45+00:00\",\"dateModified\":\"2026-08-29T01:48:45+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/97353.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/97353.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/97353.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"c++\u7c7b\u548c\u5bf9\u8c61\uff08\u4e0a\uff09\"}]},{\"@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++\u7c7b\u548c\u5bf9\u8c61\uff08\u4e0a\uff09 - \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\/97353.html","og_locale":"zh_CN","og_type":"article","og_title":"c++\u7c7b\u548c\u5bf9\u8c61\uff08\u4e0a\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u7c7b\u7684\u5b9a\u4e49 class\u4e3a\u7c7b\u7684\u5173\u952e\u5b57&#xff0c;\u6ce8\u610f\u7c7b\u5b9a\u4e49\u7ed3\u675f\u65f6\u540e\u2faf\u5206\u53f7\u4e0d\u80fd\u7701\u7565\u3002\u4e3a\u4e86\u533a\u5206\u6210\u5458\u53d8\u91cf&#xff0c;\u2f00\u822c\u4e60\u60ef\u4e0a\u6210\u5458\u53d8\u91cf\u4f1a\u52a0\u2f00\u4e2a\u7279\u6b8a\u6807\u8bc6&#xff0c;\u5982\u6210\u5458\u53d8\u91cf\u524d\u2faf\u6216\u8005\u540e\u2faf\u52a0_\u6216\u8005m \u5f00\u5934&#xff0c;\u6ce8\u610fC\u4e2d\u8fd9\u4e2a\u5e76\u4e0d\u662f\u5f3a\u5236\u7684&#xff0c;\u53ea\u662f\u2f00\u4e9b\u60ef\u4f8b&#xff0c;\u5177\u4f53\u770b\u516c\u53f8\u7684\u8981\u6c42\u3002C\u4e2dstruct\u4e5f\u53ef\u4ee5\u5b9a\u4e49\u7c7b&#xff0c;C\u517c\u5bb9C\u4e2dstruct\u7684\u2f64\u6cd5&#xff0c;\u540c\u65f6struct\u5347\u7ea7\u6210\u4e86\u7c7b&#xff0c;\u660e\u663e\u7684\u53d8\u5316\u662f struct\u4e2d\u53ef\u4ee5\u5b9a\u4e49\u51fd\u6570&amp;#","og_url":"https:\/\/www.wsisp.com\/helps\/97353.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-29T01:48:45+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260829014843-6a923a7b94cd4.png"}],"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\/97353.html","url":"https:\/\/www.wsisp.com\/helps\/97353.html","name":"c++\u7c7b\u548c\u5bf9\u8c61\uff08\u4e0a\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-29T01:48:45+00:00","dateModified":"2026-08-29T01:48:45+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/97353.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/97353.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/97353.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"c++\u7c7b\u548c\u5bf9\u8c61\uff08\u4e0a\uff09"}]},{"@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\/97353","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=97353"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/97353\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/97352"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=97353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=97353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=97353"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=97353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}