{"id":108,"date":"2026-03-22T21:51:04","date_gmt":"2026-03-22T13:51:04","guid":{"rendered":"https:\/\/codergodv.xyz\/?p=108"},"modified":"2026-03-22T21:51:22","modified_gmt":"2026-03-22T13:51:22","slug":"c11-%e7%9a%84%e7%b1%bb%e5%9e%8b%e8%bd%ac%e6%8d%a2","status":"publish","type":"post","link":"https:\/\/codergodv.xyz\/index.php\/2026\/03\/22\/c11-%e7%9a%84%e7%b1%bb%e5%9e%8b%e8%bd%ac%e6%8d%a2\/","title":{"rendered":"C++11 \u2014\u2014\u2014 \u7c7b\u578b\u8f6c\u6362"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">C\u8bed\u8a00\u4e2d\u7684\u7c7b\u578b\u8f6c\u6362<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>C\u8bed\u8a00\u548cC++\u90fd\u662f\u5f3a\u7c7b\u578b\u8bed\u8a00\uff0c\u5982\u679c\u8d4b\u503c\u8fd0\u7b97\u7b26\u5de6\u53f3\u4e24\u4fa7\u53d8\u91cf\u7684\u7c7b\u578b\u4e0d\u540c\uff0c\u6216\u5f62\u53c2\u4e0e\u5b9e\u53c2\u7684\u7c7b\u578b\u4e0d\u5339\u914d\uff0c\u6216\u8fd4\u56de\u503c\u7c7b\u578b\u4e0e\u63a5\u6536\u8fd4\u56de\u503c\u7684\u53d8\u91cf\u7c7b\u578b\u4e0d\u4e00\u81f4\uff0c\u90a3\u4e48\u5c31\u9700\u8981\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<\/blockquote>\n\n\n\n<p>C\u8bed\u8a00\u4e2d\u6709\u4e24\u79cd\u5f62\u5f0f\u7684\u7c7b\u578b\u8f6c\u6362\uff0c\u5206\u522b\u662f\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\u548c\u663e\u5f0f\u7c7b\u578b\u8f6c\u6362\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\uff1a\u7f16\u8bd1\u5668\u5728\u7f16\u8bd1\u9636\u6bb5\u81ea\u52a8\u8fdb\u884c\uff0c\u80fd\u8f6c\u5c31\u8f6c\uff0c\u4e0d\u80fd\u8f6c\u5c31\u7f16\u8bd1\u5931\u8d25\u3002<\/li>\n\n\n\n<li>\u663e\u5f0f\u7c7b\u578b\u8f6c\u6362\uff1a\u9700\u8981\u7528\u6237\u81ea\u5df1\u5904\u7406\uff0c\u4ee5<code>(\u6307\u5b9a\u7c7b\u578b)\u53d8\u91cf<\/code>\u7684\u65b9\u5f0f\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u53ea\u6709\u76f8\u8fd1\u7c7b\u578b\u4e4b\u95f4\u624d\u80fd\u53d1\u751f\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\uff0c\u6bd4\u5982int\u548cdouble\u8868\u793a\u7684\u90fd\u662f\u6570\u503c\uff0c\u53ea\u4e0d\u8fc7\u5b83\u4eec\u8868\u793a\u7684\u8303\u56f4\u548c\u7cbe\u5ea6\u4e0d\u540c\u3002\u800c\u6307\u9488\u7c7b\u578b\u8868\u793a\u7684\u662f\u5730\u5740\u7f16\u53f7\uff0c\u56e0\u6b64\u6574\u578b\u548c\u6307\u9488\u7c7b\u578b\u4e4b\u95f4\u4e0d\u4f1a\u8fdb\u884c\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\uff0c\u5982\u679c\u9700\u8981\u8f6c\u6362\u5219\u53ea\u80fd\u8fdb\u884c\u663e\u5f0f\u7c7b\u578b\u8f6c\u6362\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int main()\n{\n    \/\/\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\n    int i = 1;\n    double d = i;\n    cout &lt;&lt; i &lt;&lt; endl;\n    cout &lt;&lt; d &lt;&lt; endl;\n\n    \/\/\u663e\u5f0f\u7c7b\u578b\u8f6c\u6362\n    int* p = &amp;i;\n    int address = (int)p;\n    cout &lt;&lt; p &lt;&lt; endl;\n    cout &lt;&lt; address &lt;&lt; endl;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e3a\u4ec0\u4e48C++\u9700\u8981\u56db\u79cd\u7c7b\u578b\u8f6c\u6362<\/h2>\n\n\n\n<p>C\u98ce\u683c\u7684\u8f6c\u6362\u683c\u5f0f\u867d\u7136\u5f88\u7b80\u5355\uff0c\u4f46\u4e5f\u6709\u5f88\u591a\u7f3a\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u53ef\u80fd\u4f1a\u51fa\u95ee\u9898\uff0c\u6bd4\u5982\u6570\u636e\u7cbe\u5ea6\u4e22\u5931\u3002<\/li>\n\n\n\n<li>\u663e\u5f0f\u7c7b\u578b\u8f6c\u6362\u5c06\u6240\u6709\u60c5\u51b5\u6df7\u5408\u5728\u4e00\u8d77\uff0c\u8f6c\u6362\u7684\u53ef\u89c6\u6027\u6bd4\u8f83\u5dee\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u56e0\u6b64C++\u4e3a\u4e86\u52a0\u5f3a\u7c7b\u578b\u8f6c\u6362\u7684\u53ef\u89c6\u6027\uff0c\u5f15\u5165\u4e86\u56db\u79cd\u547d\u540d\u7684\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u64cd\u4f5c\u7b26\uff0c\u5206\u522b\u662f<a href=\"https:\/\/so.csdn.net\/so\/search?q=static_cast&amp;spm=1001.2101.3001.7020\">static_cast<\/a>\u3001reinterpret_cast\u3001const_cast\u548cdynamic_cast\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/so.csdn.net\/so\/search?q=C%2B%2B\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362&amp;spm=1001.2101.3001.7020\">C++\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362<\/a><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">static_cast<\/h3>\n\n\n\n<p>static_cast\u7528\u4e8e\u76f8\u8fd1\u7c7b\u578b\u4e4b\u95f4\u7684\u8f6c\u6362\uff0c\u7f16\u8bd1\u5668\u9690\u5f0f\u6267\u884c\u7684\u4efb\u4f55\u7c7b\u578b\u8f6c\u6362\u90fd\u53ef\u7528static_cast\uff0c\u4f46\u5b83\u4e0d\u80fd\u7528\u4e8e\u4e24\u4e2a\u4e0d\u76f8\u5173\u7c7b\u578b\u4e4b\u95f4\u8f6c\u6362\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int main()\n{\n    double d = 12.34;\n    int a = static_cast&lt;int&gt;(d);\n    cout &lt;&lt; a &lt;&lt; endl;\n\n    int* p = &amp;a;\n    \/\/ int address = static_cast&lt;int&gt;(p); \/\/error\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">reinterpret_cast<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>int main()\n{\n    int a = 10;\n    int* p = &amp;a;\n    int address = reinterpret_cast&lt;int&gt;(p);\n    cout &lt;&lt; address &lt;&lt; endl;\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>reinterpret_cast\u8fd8\u6709\u4e00\u4e2a\u975e\u5e38bug\u7684\u7528\u6cd5\uff0c\u6bd4\u5982\u5728\u4e0b\u9762\u7684\u4ee3\u7801\u4e2d\u5c06\u5e26\u53c2\u5e26\u8fd4\u56de\u503c\u7684\u51fd\u6570\u6307\u9488\u8f6c\u6362\u6210\u4e86\u65e0\u53c2\u65e0\u8fd4\u56de\u503c\u7684\u51fd\u6570\u6307\u9488\uff0c\u5e76\u4e14\u8fd8\u53ef\u4ee5\u7528\u8f6c\u6362\u540e\u51fd\u6570\u6307\u9488\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>typedef void(*FUNC)();\nint DoSomething(int i)\n{\n    cout &lt;&lt; \"DoSomething: \" &lt;&lt; i &lt;&lt; endl;\n    return 0;\n}\nint main()\n{\n    FUNC f = reinterpret_cast&lt;FUNC&gt;(DoSomething);\n    f();\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>\u8bf4\u660e\u4e00\u4e0b\uff1a<\/strong> \u7528\u8f6c\u6362\u540e\u7684\u51fd\u6570\u6307\u9488\u8c03\u7528\u8be5\u51fd\u6570\u65f6\u6ca1\u6709\u4f20\u5165\u53c2\u6570\uff0c\u56e0\u6b64\u8fd9\u91cc\u6253\u5370\u51fa\u53c2\u6570<code>i<\/code>\u7684\u503c\u662f\u4e00\u4e2a\u968f\u673a\u503c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/so.csdn.net\/so\/search?q=const_cast&amp;spm=1001.2101.3001.7020\">const_cast<\/a><\/h3>\n\n\n\n<p>const_cast\u7528\u4e8e\u5220\u9664\u53d8\u91cf\u7684const\u5c5e\u6027\uff0c\u8f6c\u6362\u540e\u5c31\u53ef\u4ee5\u5bf9const\u53d8\u91cf\u7684\u503c\u8fdb\u884c\u4fee\u6539\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int main()\n{\n    const int a = 2;\n    int* p = const_cast&lt;int*&gt;(&amp;a);\n    *p = 3;\n    cout &lt;&lt; a &lt;&lt; endl;  \/\/2\n    cout &lt;&lt; *p &lt;&lt; endl; \/\/3\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>\u8bf4\u660e\u4e00\u4e0b\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4ee3\u7801\u4e2d\u7528const_cast\u5220\u9664\u4e86\u53d8\u91cfa\u7684\u5730\u5740\u7684const\u5c5e\u6027\uff0c\u8fd9\u65f6\u5c31\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a\u6307\u9488\u6765\u4fee\u6539\u53d8\u91cfa\u7684\u503c\u3002<\/li>\n\n\n\n<li>\u7531\u4e8e\u7f16\u8bd1\u5668\u8ba4\u4e3aconst\u4fee\u9970\u7684\u53d8\u91cf\u662f\u4e0d\u4f1a\u88ab\u4fee\u6539\u7684\uff0c\u56e0\u6b64\u4f1a\u5c06const\u4fee\u9970\u7684\u53d8\u91cf\u5b58\u653e\u5230\u5bc4\u5b58\u5668\u5f53\u4e2d\uff0c\u5f53\u9700\u8981\u8bfb\u53d6const\u53d8\u91cf\u65f6\u5c31\u4f1a\u76f4\u63a5\u4ece\u5bc4\u5b58\u5668\u4e2d\u8fdb\u884c\u8bfb\u53d6\uff0c\u800c\u6211\u4eec\u4fee\u6539\u7684\u5b9e\u9645\u4e0a\u662f\u5185\u5b58\u4e2d\u7684a\u7684\u503c\uff0c\u56e0\u6b64\u6700\u7ec8\u6253\u5370\u51faa\u7684\u503c\u662f\u672a\u4fee\u6539\u4e4b\u524d\u7684\u503c\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u4e0d\u60f3\u8ba9\u7f16\u8bd1\u5668\u5c06const\u53d8\u91cf\u4f18\u5316\u5230\u5bc4\u5b58\u5668\u5f53\u4e2d\uff0c\u53ef\u4ee5\u7528volatile\u5173\u952e\u5b57\u5bf9const\u53d8\u91cf\u8fdb\u884c\u4fee\u9970\uff0c\u8fd9\u65f6\u5f53\u8981\u8bfb\u53d6\u8fd9\u4e2aconst\u53d8\u91cf\u65f6\u7f16\u8bd1\u5668\u5c31\u4f1a\u4ece\u5185\u5b58\u4e2d\u8fdb\u884c\u8bfb\u53d6\uff0c\u5373\u4fdd\u6301\u4e86\u8be5\u53d8\u91cf\u5728\u5185\u5b58\u4e2d\u7684\u53ef\u89c1\u6027\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">dynamic_cast<\/h3>\n\n\n\n<p>dynamic_cast\u7528\u4e8e\u5c06\u7236\u7c7b\u7684\u6307\u9488\uff08\u6216\u5f15\u7528\uff09\u8f6c\u6362\u6210\u5b50\u7c7b\u7684\u6307\u9488\uff08\u6216\u5f15\u7528\uff09\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5411\u4e0a\u8f6c\u578b\u4e0e\u5411\u4e0b\u8f6c\u578b<\/p>\n<\/blockquote>\n\n\n\n<p><strong>\u5411\u4e0a\u8f6c\u578b\uff1a<\/strong> \u5b50\u7c7b\u7684\u6307\u9488\uff08\u6216\u5f15\u7528\uff09\u2192 \u7236\u7c7b\u7684\u6307\u9488\uff08\u6216\u5f15\u7528\uff09\u3002<br><strong>\u5411\u4e0b\u8f6c\u578b\uff1a<\/strong> \u7236\u7c7b\u7684\u6307\u9488\uff08\u6216\u5f15\u7528\uff09\u2192 \u5b50\u7c7b\u7684\u6307\u9488\uff08\u6216\u5f15\u7528\uff09\u3002<\/p>\n\n\n\n<p>\u5176\u4e2d\uff0c\u5411\u4e0a\u8f6c\u578b\u5c31\u662f\u6240\u8bf4\u7684\u5207\u5272\/\u5207\u7247\uff0c\u662f\u8bed\u6cd5\u5929\u7136\u652f\u6301\u7684\uff0c\u4e0d\u9700\u8981\u8fdb\u884c\u8f6c\u6362\uff0c\u800c\u5411\u4e0b\u8f6c\u578b\u662f\u8bed\u6cd5\u4e0d\u652f\u6301\u7684\uff0c\u9700\u8981\u8fdb\u884c\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5411\u4e0b\u8f6c\u578b\u7684\u5b89\u5168\u95ee\u9898<\/p>\n<\/blockquote>\n\n\n\n<p>\u5411\u4e0b\u8f6c\u578b\u5206\u4e3a\u4e24\u79cd\u60c5\u51b5\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5982\u679c\u7236\u7c7b\u7684\u6307\u9488\uff08\u6216\u5f15\u7528\uff09\u6307\u5411\u7684\u662f\u4e00\u4e2a\u7236\u7c7b\u5bf9\u8c61\uff0c\u90a3\u4e48\u5c06\u5176\u8f6c\u6362\u4e3a\u5b50\u7c7b\u7684\u6307\u9488\uff08\u6216\u5f15\u7528\uff09\u662f\u4e0d\u5b89\u5168\u7684\uff0c\u56e0\u4e3a\u8f6c\u6362\u540e\u53ef\u80fd\u4f1a\u8bbf\u95ee\u5230\u5b50\u7c7b\u7684\u8d44\u6e90\uff0c\u800c\u8fd9\u4e2a\u8d44\u6e90\u662f\u7236\u7c7b\u5bf9\u8c61\u6240\u6ca1\u6709\u7684\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u7236\u7c7b\u7684\u6307\u9488\uff08\u6216\u5f15\u7528\uff09\u6307\u5411\u7684\u662f\u4e00\u4e2a\u5b50\u7c7b\u5bf9\u8c61\uff0c\u90a3\u4e48\u5c06\u5176\u8f6c\u6362\u4e3a\u5b50\u7c7b\u7684\u6307\u9488\uff08\u6216\u5f15\u7528\uff09\u5219\u662f\u5b89\u5168\u7684\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u4f7f\u7528C\u98ce\u683c\u7684\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u8fdb\u884c\u5411\u4e0b\u8f6c\u578b\u662f\u4e0d\u5b89\u5168\u7684\uff0c\u56e0\u4e3a\u6b64\u65f6\u65e0\u8bba\u7236\u7c7b\u7684\u6307\u9488\uff08\u6216\u5f15\u7528\uff09\u6307\u5411\u7684\u662f\u7236\u7c7b\u5bf9\u8c61\u8fd8\u662f\u5b50\u7c7b\u5bf9\u8c61\u90fd\u4f1a\u8fdb\u884c\u8f6c\u6362\u3002\u800c\u4f7f\u7528dynamic_cast\u8fdb\u884c\u5411\u4e0b\u8f6c\u578b\u5219\u662f\u5b89\u5168\u7684\uff0c\u5982\u679c\u7236\u7c7b\u7684\u6307\u9488\uff08\u6216\u5f15\u7528\uff09\u6307\u5411\u7684\u662f\u5b50\u7c7b\u5bf9\u8c61\u90a3\u4e48dynamic_cast\u4f1a\u8f6c\u6362\u6210\u529f\uff0c\u4f46\u5982\u679c\u7236\u7c7b\u7684\u6307\u9488\uff08\u6216\u5f15\u7528\uff09\u6307\u5411\u7684\u662f\u7236\u7c7b\u5bf9\u8c61\u90a3\u4e48dynamic_cast\u4f1a\u8f6c\u6362\u5931\u8d25\u5e76\u8fd4\u56de\u4e00\u4e2a\u7a7a\u6307\u9488\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class A\n{\npublic:\n    virtual void f()\n    {}\n};\nclass B : public A\n{};\nvoid func(A* pa)\n{\n    B* pb1 = (B*)pa;               \/\/\u4e0d\u5b89\u5168\n    B* pb2 = dynamic_cast&lt;B*&gt;(pa); \/\/\u5b89\u5168\n\n    cout &lt;&lt; \"pb1: \" &lt;&lt; pb1 &lt;&lt; endl;\n    cout &lt;&lt; \"pb2: \" &lt;&lt; pb2 &lt;&lt; endl;\n}\nint main()\n{\n    A a;\n    B b;\n    func(&amp;a);\n    func(&amp;b);\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u5982\u679c\u4f20\u5165func\u51fd\u6570\u7684\u662f\u5b50\u7c7b\u5bf9\u8c61\u7684\u5730\u5740\uff0c\u90a3\u4e48\u5728\u8f6c\u6362\u540epb1\u548cpb2\u90fd\u4f1a\u6709\u5bf9\u5e94\u7684\u5730\u5740\uff0c\u4f46\u5982\u679c\u4f20\u5165func\u51fd\u6570\u7684\u662f\u7236\u7c7b\u5bf9\u8c61\u7684\u5730\u5740\uff0c\u90a3\u4e48\u8f6c\u6362\u540epb1\u4f1a\u6709\u5bf9\u5e94\u7684\u5730\u5740\uff0c\u800cpb2\u5219\u662f\u4e00\u4e2a\u7a7a\u6307\u9488\u3002<\/p>\n\n\n\n<p><strong>\u8bf4\u660e\u4e00\u4e0b\uff1a<\/strong> dynamic_cast\u53ea\u80fd\u7528\u4e8e\u542b\u6709\u865a\u51fd\u6570\u7684\u7c7b\uff0c\u56e0\u4e3a\u8fd0\u884c\u65f6\u7c7b\u578b\u68c0\u67e5\u9700\u8981\u8fd0\u884c\u65f6\u7684\u7c7b\u578b\u4fe1\u606f\uff0c\u800c\u8fd9\u4e2a\u4fe1\u606f\u662f\u5b58\u50a8\u5728\u865a\u51fd\u6570\u8868\u4e2d\u7684\uff0c\u53ea\u6709\u5b9a\u4e49\u4e86\u865a\u51fd\u6570\u7684\u7c7b\u624d\u6709\u865a\u51fd\u6570\u8868\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">explicit<\/h3>\n\n\n\n<p>explicit\u7528\u6765\u4fee\u9970\u6784\u9020\u51fd\u6570\uff0c\u4ece\u800c\u7981\u6b62\u5355\u53c2\u6570\u6784\u9020\u51fd\u6570\u7684\u9690\u5f0f\u8f6c\u6362\u3002\u6bd4\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class A\n{\npublic:\n    explicit A(int a)\n    {\n        cout &lt;&lt; \"A(int a)\" &lt;&lt; endl;\n    }\n    A(const A&amp; a)\n    {\n        cout &lt;&lt; \"A(const A&amp; a)\" &lt;&lt; endl;\n    }\nprivate:\n    int _a;\n};\nint main()\n{\n    A a1(1);\n    \/\/A a2 = 1; \/\/error\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>\u5728\u8bed\u6cd5\u4e0a\uff0c\u4ee3\u7801\u4e2d\u7684A a2 = 1\u7b49\u4ef7\u4e8e\u4ee5\u4e0b\u4e24\u53e5\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>A tmp(1);  \/\/\u5148\u6784\u9020\nA a2(tmp); \/\/\u518d\u62f7\u8d1d\u6784\u9020<\/code><\/pre>\n\n\n\n<p>\u6240\u4ee5\u5728\u65e9\u671f\u7684\u7f16\u8bd1\u5668\u4e2d\uff0c\u5f53\u7f16\u8bd1\u5668\u9047\u5230A a2 = 1\u8fd9\u53e5\u4ee3\u7801\u65f6\uff0c\u4f1a\u5148\u6784\u9020\u4e00\u4e2a\u4e34\u65f6\u5bf9\u8c61\uff0c\u518d\u7528\u8fd9\u4e2a\u4e34\u65f6\u5bf9\u8c61\u62f7\u8d1d\u6784\u9020a2\u3002\u4f46\u662f\u73b0\u5728\u7684\u7f16\u8bd1\u5668\u5df2\u7ecf\u505a\u4e86\u4f18\u5316\uff0c\u5f53\u9047\u5230A a2 = 1\u8fd9\u53e5\u4ee3\u7801\u65f6\uff0c\u4f1a\u76f4\u63a5\u6309\u7167A a2(1)\u7684\u65b9\u5f0f\u8fdb\u884c\u5904\u7406\uff0c\u8fd9\u4e5f\u53eb\u505a\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n\n\n\n<p>\u4f46\u5bf9\u4e8e\u5355\u53c2\u6570\u7684\u81ea\u5b9a\u4e49\u7c7b\u578b\u6765\u8bf4\uff0cA a2 = 1\u8fd9\u79cd\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u4e0d\u662f\u5f88\u597d\uff0c\u56e0\u6b64\u53ef\u4ee5\u7528explicit\u4fee\u9970\u5355\u53c2\u6570\u7684\u6784\u9020\u51fd\u6570\uff0c\u4ece\u800c\u7981\u6b62\u5355\u53c2\u6570\u6784\u9020\u51fd\u6570\u7684\u9690\u5f0f\u8f6c\u6362\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">RTTI<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>RTTI\uff08Run-Time Type Identification\uff09\u5c31\u662f\u8fd0\u884c\u65f6\u7c7b\u578b\u8bc6\u522b\u3002<\/p>\n<\/blockquote>\n\n\n\n<p>C++\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\u6765\u652f\u6301RTTI\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>typeid\uff1a\u5728\u8fd0\u884c\u65f6\u8bc6\u522b\u51fa\u4e00\u4e2a\u5bf9\u8c61\u7684\u7c7b\u578b\u3002<\/li>\n\n\n\n<li>dynamic_cast\uff1a\u5728\u8fd0\u884c\u65f6\u8bc6\u522b\u51fa\u4e00\u4e2a\u7236\u7c7b\u7684\u6307\u9488\uff08\u6216\u5f15\u7528\uff09\u6307\u5411\u7684\u662f\u7236\u7c7b\u5bf9\u8c61\u8fd8\u662f\u5b50\u7c7b\u5bf9\u8c61\u3002<\/li>\n\n\n\n<li>decltype\uff1a\u5728\u8fd0\u884c\u65f6\u63a8\u6f14\u51fa\u4e00\u4e2a\u8868\u8fbe\u5f0f\u6216\u51fd\u6570\u8fd4\u56de\u503c\u7684\u7c7b\u578b\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u5e38\u89c1\u9762\u8bd5\u9898<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>1\u3001C++\u4e2d\u76844\u79cd\u7c7b\u578b\u8f6c\u6362\u5206\u522b\u662f\uff1a<strong><em>_ \u3001<\/em><\/strong><em> \u3001<strong> \u3001_<\/strong><\/em>\u3002<\/p>\n<\/blockquote>\n\n\n\n<p>\u5206\u522b\u662fstatic_cast\u3001reinterpret_cast\u3001const_cast\u548cdynamic_cast\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>2\u3001\u8bf4\u8bf44\u79cd\u7c7b\u578b\u8f6c\u6362\u7684\u5e94\u7528\u573a\u666f\u3002<\/p>\n<\/blockquote>\n\n\n\n<ul class=\"wp-block-list\">\n<li>static_cast\u7528\u4e8e\u76f8\u8fd1\u7c7b\u578b\u7684\u7c7b\u578b\u4e4b\u95f4\u7684\u8f6c\u6362\uff0c\u7f16\u8bd1\u5668\u9690\u5f0f\u6267\u884c\u7684\u4efb\u4f55\u7c7b\u578b\u8f6c\u6362\u90fd\u53ef\u7528static_cast\u3002<\/li>\n\n\n\n<li>reinterpret_cast\u7528\u4e8e\u4e24\u4e2a\u4e0d\u76f8\u5173\u7c7b\u578b\u4e4b\u95f4\u7684\u8f6c\u6362\u3002<\/li>\n\n\n\n<li>const_cast\u7528\u4e8e\u5220\u9664\u53d8\u91cf\u7684const\u5c5e\u6027\uff0c\u65b9\u4fbf\u8d4b\u503c\u3002<\/li>\n\n\n\n<li>dynamic_cast\u7528\u4e8e\u5b89\u5168\u7684\u5c06\u7236\u7c7b\u7684\u6307\u9488\uff08\u6216\u5f15\u7528\uff09\u8f6c\u6362\u6210\u5b50\u7c7b\u7684\u6307\u9488\uff08\u6216\u5f15\u7528\uff09\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>C\u8bed\u8a00\u4e2d\u7684\u7c7b\u578b\u8f6c\u6362 C\u8bed\u8a00\u548cC++\u90fd\u662f\u5f3a\u7c7b\u578b\u8bed\u8a00\uff0c\u5982\u679c\u8d4b\u503c\u8fd0\u7b97\u7b26\u5de6\u53f3\u4e24\u4fa7\u53d8\u91cf\u7684\u7c7b\u578b\u4e0d\u540c\uff0c\u6216\u5f62\u53c2\u4e0e\u5b9e\u53c2\u7684\u7c7b\u578b\u4e0d\u5339 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,1],"tags":[22,24],"class_list":["post-108","post","type-post","status-publish","format-standard","hentry","category-cpp","category-learn","tag-c11","tag-24"],"_links":{"self":[{"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/posts\/108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=108"}],"version-history":[{"count":2,"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/posts\/108\/revisions"}],"predecessor-version":[{"id":110,"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/posts\/108\/revisions\/110"}],"wp:attachment":[{"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codergodv.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}