{"id":384578,"date":"2021-03-11T10:41:07","date_gmt":"2021-03-11T02:41:07","guid":{"rendered":"http:\/\/4563.org\/?p=384578"},"modified":"2021-03-11T10:41:07","modified_gmt":"2021-03-11T02:41:07","slug":"%e6%88%91%e6%95%b4%e7%90%86%e4%ba%86%e8%bf%99%e7%af%87%e6%8c%87%e9%92%88%e7%9a%84%e7%9f%a5%e8%af%86%e7%82%b9%ef%bc%8c%e6%83%b3%e5%bf%85%e5%af%b9%e4%bd%a0%e6%9c%89%e7%94%a8","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=384578","title":{"rendered":"\u6211\u6574\u7406\u4e86\u8fd9\u7bc7\u6307\u9488\u7684\u77e5\u8bc6\u70b9\uff0c\u60f3\u5fc5\u5bf9\u4f60\u6709\u7528"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6211\u6574\u7406\u4e86\u8fd9\u7bc7\u6307\u9488\u7684\u77e5\u8bc6\u70b9\uff0c\u60f3\u5fc5\u5bf9\u4f60\u6709\u7528               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yiouejv <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h3>\u6307\u9488\u548c\u5f15\u7528\u7684\u533a\u522b<\/h3>\n<ol>\n<li>\u975e\u7a7a\u533a\u522b: \u4efb\u4f55\u60c5\u51b5\u4e0b\u90fd\u4e0d\u80fd\u4f7f\u7528\u6307\u5411\u7a7a\u503c\u7684\u5f15\u7528\uff0c\u4e00\u4e2a\u5f15\u7528\u5fc5\u987b\u603b\u662f\u6307\u5411\u67d0\u4e9b\u5bf9\u8c61\u3002 \u6307\u9488\u53ef\u4ee5\u6307\u5411\u7a7a\u3002<\/li>\n<li>\u5408\u6cd5\u6027\u533a\u522b: \u5f15\u7528\u5728\u4f7f\u7528\u4e4b\u524d\u4e0d\u9700\u8981\u6d4b\u8bd5\u5408\u6cd5\u6027\uff0c\u6307\u9488\u5e94\u8be5\u603b\u662f\u8981\u88ab\u6d4b\u8bd5\uff0c\u9632\u6b62\u5176\u4e3a\u7a7a<\/li>\n<li>\u53ef\u4fee\u6539\u6027\u533a\u522b: \u5f15\u7528\u5728\u521d\u59cb\u5316\u65f6\u6307\u5b9a\u5bf9\u8c61\uff0c\u4ee5\u540e\u4e0d\u80fd\u4fee\u6539\u3002<\/li>\n<\/ol>\n<h3>\u6307\u9488\u4f20\u9012\u52a8\u6001\u5185\u5b58<\/h3>\n<p><strong>\u4f8b 1: \u7a0b\u5e8f\u6d4b\u8bd5\u540e\u4f1a\u6709\u4ec0\u4e48\u7ed3\u679c\uff1f<\/strong><\/p>\n<pre><code>#include&lt;iostream&gt; #include&lt;cstring&gt; using namespace std;  void getMemory(char*p, int num) {     p = (char*)malloc(sizeof(char) * num); }  int main(int argc, const char* argv[]) {     char *str = NULL;     getMemory(str, 100);     strcpy(str, \"hello\");     return 0; } <\/code><\/pre>\n<p>\u95ee\u9898\u51fa\u73b0\u5728<code>getMemory<\/code>\u91cc\uff0c\u7f16\u8bd1\u5668\u603b\u662f\u4e3a\u51fd\u6570\u7684\u6bcf\u4e2a\u53c2\u6570\u5236\u4f5c\u4e00\u4e2a\u4e34\u65f6\u526f\u672c\u3002\u5728\u672c\u9898\u4e2d\uff0cp \u4e3a str \u7684\u62f7\u8d1d\uff0cp \u7533\u8bf7\u4e86\u4e00\u4e2a\u65b0\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u4f46\u662f\u5e76\u6ca1\u6709\u5f71\u54cd\u5230 str\uff0cstr \u8fd8\u662f NULL\uff0c\u518d\u8c03\u7528 strcpy(), \u5219\u4f1a\u4f7f\u4ee3\u7801\u5d29\u6e83\uff0c\u5e76\u4e14 p \u7533\u8bf7\u7684\u5185\u5b58\u4e5f\u4e00\u76f4\u6ca1\u7528\u91ca\u653e\uff0c\u9020\u6210\u5185\u5b58\u6cc4\u9732\u3002<\/p>\n<p>\u6b63\u786e\u7684\u65b9\u6cd5\u662f\u628a\u5f80 getMemory \u5185\u4f20\u5165 str \u7684\u5730\u5740\u3002<\/p>\n<pre><code>#include&lt;iostream&gt; #include&lt;cstring&gt; using namespace std;  void getMemory(char**p, int num) {     *p = (char*)malloc(sizeof(char) * num); }  int main(int argc, const char* argv[]) {     char *str = NULL;     getMemory(&amp;str, 100);     strcpy(str, \"hello\");     cout &lt;&lt; str &lt;&lt; endl;     return 0; } <\/code><\/pre>\n<p>\u4e0d\u8fc7\u8fd9\u6837\u5199\u6709\u4e9b\u9ebb\u70e6\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u628a\u7533\u8bf7\u597d\u7684\u5185\u5b58\u8fd4\u56de\u3002<\/p>\n<pre><code>#include&lt;iostream&gt; #include&lt;cstring&gt; using namespace std;  char* getMemory(int num) {     return (char*)malloc(sizeof(char) * num); }  int main(int argc, const char* argv[]) {     char *str = NULL;     str = getMemory(100);     strcpy(str, \"hello\");     cout &lt;&lt; str &lt;&lt; endl;     return 0; } <\/code><\/pre>\n<p><strong>\u4f8b 2: \u8fd9\u4e2a\u51fd\u6570\u6709\u4ec0\u4e48\u95ee\u9898?<\/strong><\/p>\n<pre><code>char* strA() {     char str[] = \"hello world\";     return str; } <\/code><\/pre>\n<p>str \u91cc\u5b58\u7684\u5730\u5740\u662f\u51fd\u6570 strA \u6808\u5e27\u91cc<code>\"hello world\"<\/code>\u7684\u9996\u5730\u5740\uff0c\u51fd\u6570\u8c03\u7528\u5b8c\u6210\uff0c\u4e34\u65f6\u7a7a\u95f4\u88ab\u91cd\u7f6e\u3002<\/p>\n<p>\u5982\u679c\u8981\u83b7\u5f97\u6b63\u786e\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a<\/p>\n<pre><code>char* strA() {     char *str = \"hello world\";     return str; } <\/code><\/pre>\n<p>\u9996\u5148\u8981\u641e\u6e05\u695a<code>char str[]<\/code>, <code>char* str<\/code>, <\/p>\n<p><code>char str[]<\/code> \u5206\u914d\u7684\u662f\u4e00\u4e2a\u5c40\u90e8\u6570\u7ec4\uff0c<\/p>\n<p><code>char* str<\/code> \u5206\u914d\u7684\u662f\u4e00\u4e2a\u6307\u9488\u904d\u5386\uff0c<\/p>\n<p>\u5c40\u90e8\u6570\u7ec4\u662f\u5c40\u90e8\u53d8\u91cf\uff0c\u5b83\u5bf9\u5e94\u7684\u662f\u5185\u5b58\u4e2d\u7684\u6808\u3002\u6307\u9488\u53d8\u91cf\u662f\u5168\u5c40\u53d8\u91cf\uff0c\u5b83\u5bf9\u5e94\u7684\u662f\u5185\u5b58\u4e2d\u7684\u5168\u5c40\u533a\u57df\u3002<\/p>\n<p>\u4e0d\u8fc7\u4e0a\u8ff0\u4ee3\u7801\u53ea\u80fd c \u8bed\u8a00\u8fd9\u4e48\u5199\uff0cc++\u4e0d\u5141\u8bb8 <\/p>\n<p><code>ISO C++ forbids converting a string constant to \u2018char*\u2019<\/code><\/p>\n<p>\u53ef\u4ee5\u8fd9\u4e48\u5199\uff1a<\/p>\n<pre><code>char* strA() {     static char str[] = \"hello world\";     return str; } <\/code><\/pre>\n<p><strong>\u4f8b 3: \u4e0b\u9762\u4ee3\u7801\u7684\u8f93\u51fa\u7ed3\u679c\u662f\u4ec0\u4e48\uff1f<\/strong><\/p>\n<pre><code>#include&lt;iostream&gt; using namespace std;  class A { public:     A() { m_a = 1; m_b = 2; }     ~A(){}     void fun() { printf(\"%d%d\", m_a, m_b);} private:     int m_a;     int m_b; };  class B { public:     B() {m_c = 3;}     ~B();     void fun() {printf(\"%d\", m_c);} private:     int m_c; };   int main(int argc, const char* argv[]) {     A a;     B *pb = (B*)(&amp;a);     pb-&gt;fun();     return 0; } <\/code><\/pre>\n<p>\u8fd9\u9053\u9898\u7684\u76ee\u7684\u5c31\u662f\u8003\u5bdf\u4f60\u5bf9\u5185\u5b58\u504f\u79fb\u7684\u7406\u89e3\uff0c<\/p>\n<p><code>B* pb = (B*)(&amp;a);<\/code>, \u8fd9\u662f\u4e00\u4e2a\u91ce\u86ee\u7684\u8f6c\u6362\uff0c\u5f3a\u5236\u628a a \u5730\u5740\u5185\u5bb9\u770b\u6210\u4e00\u4e2a B \u7c7b\u7684\u5bf9\u8c61\uff0cpb \u6307\u5411\u7684\u662f a \u7c7b\u7684\u5185\u5b58\u7a7a\u95f4, \u628a a \u7c7b\u7a7a\u95f4\u6309\u7167 B \u7c7b\u7684\u7ed3\u6784\u6765\u89e3\u8bfb\u3002<\/p>\n<p> <img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/03\/20210311_604a62785547d.png\" alt=\"\u6211\u6574\u7406\u4e86\u8fd9\u7bc7\u6307\u9488\u7684\u77e5\u8bc6\u70b9\uff0c\u60f3\u5fc5\u5bf9\u4f60\u6709\u7528\" \/> <\/p>\n<h3>\u51fd\u6570\u6307\u9488<\/h3>\n<p><strong>\u4f8b 1: \u627e\u51fa\u4e0b\u5217\u7a0b\u5e8f\u7684\u9519\u8bef<\/strong><\/p>\n<pre><code>#include&lt;iostream&gt; using namespace std;  int Max(int x, int y) {  return x &gt; y ? x : y; }  int main(int argc, char const *argv[]) {  int *p = &amp;Max;  cout &lt;&lt; p(2, 1) &lt;&lt; endl;  return 0; } <\/code><\/pre>\n<p>\u8fd9\u9053\u7a0b\u5e8f\u63d0\u5b58\u5728\u7740\u51fd\u6570\u6307\u9488\u7684\u9519\u8bef\u4f7f\u7528\u95ee\u9898\uff0c\u6b63\u786e\u7684\u5199\u6cd5\u4e3a: <code>int (*p)(int, int) = &amp;Max;<\/code><\/p>\n<p><code>int *p<\/code> p \u662f int \u578b\u7684\u6307\u9488<\/p>\n<p><code>int *p(int, int)<\/code>, p \u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u8fd4\u56de\u503c\u4e3a<code>int*<\/code><\/p>\n<p><code>int (*p)(int, int)<\/code>, p \u662f\u4e00\u4e2a\u6307\u9488\uff0c\u6307\u5411\u51fd\u6570\u7684\u5730\u5740\uff0c\u51fd\u6570\u7684\u8fd4\u56de\u503c\u4e3a int<\/p>\n<p><strong>\u4f8b 2: \u4e0b\u9762\u7684\u6570\u636e\u58f0\u660e\u90fd\u4ee3\u8868\u4ec0\u4e48\uff1f<\/strong><\/p>\n<pre><code>float(**def)[10]; double*(*gh)[10]; double(*f[10])(); int*((*b)[10]); long(*fun)(int) int(*(*F)(int, int))(int) <\/code><\/pre>\n<p>\u7b54\u6848\u5982\u4e0b:<\/p>\n<pre><code>float(**def)[10];  \/\/ def \u662f\u4e8c\u7ea7\u6307\u9488\uff0c\u6307\u5411\u4e00\u7ea7\u6307\u9488\uff0c\u4e00\u7ea7\u6307\u9488\u6307\u5411\u6570\u7ec4\uff0c\u6570\u7ec4\u7684\u5927\u5c0f\u4e3a 10\uff0c\u6570\u7ec4\u5143\u7d20\u7c7b\u578b\u4e3a float double*(*gh)[10];  \/\/ gh \u662f\u4e00\u7ea7\u6307\u9488\uff0c\u6307\u5411\u4e00\u4e2a\u6570\u7ec4\uff0c\u6570\u7ec4\u5927\u5c0f\u4e3a 10\uff0c\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u578b\u4e3a double* double(*f[10])();  \/\/ f \u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u6570\u7ec4\u5927\u5c0f\u4e3a 10\uff0c\u6570\u7ec4\u7684\u5143\u7d20\u7c7b\u578b\u4e3a\u6307\u9488\uff0c\u6307\u9488\u6307\u5411\u7684\u7c7b\u578b\u4e3a double() \u7684\u51fd\u6570 int*((*b)[10]);  \/\/ b \u662f\u4e00\u4e2a\u6307\u9488\uff0c\u6307\u5411\u4e00\u4e2a\u6570\u7ec4\uff0c\u6570\u7ec4\u7684\u5927\u5c0f\u4e3a 10\uff0c\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u578b\u4e3a int* long(*fun)(int)  \/\/ fun \u662f\u4e00\u4e2a\u51fd\u6570\u6307\u9488\uff0c\u6307\u5411 long(int) \u578b\u7684\u51fd\u6570 int(*(*F)(int, int))(int)  \/\/ F \u662f\u4e00\u4e2a\u6307\u9488\uff0c\u6307\u5411\u4e00\u4e2a\u51fd\u6570\uff0c\u51fd\u6570\u7684\u53c2\u6570\u4e3a(int, int), \u51fd\u6570\u7684\u8fd4\u56de\u503c\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u6307\u5411\u4e00\u4e2a\u51fd\u6570\uff0c\u51fd\u6570\u7684\u53c2\u6570\u4e3a(int), \u51fd\u6570\u7684\u8fd4\u56de\u503c\u4e3a int <\/code><\/pre>\n<h3>\u6307\u9488\u6570\u7ec4\u548c\u6570\u7ec4\u6307\u9488<\/h3>\n<p><strong>\u4f8b 1: \u4ee5\u4e0b\u7a0b\u5e8f\u7684\u8f93\u51fa\u662f\u4ec0\u4e48\uff1f<\/strong><\/p>\n<pre><code>#include&lt;iostream&gt; using namespace std;  int main(int argc, char const *argv[]) {     int v[2][10] = {         {1,2,3,4,5,6,7,8,9,10},         {11,12,13,14,15,16,17,18,19,20},     };     int (*a)[10] = v;       \/\/ \u6570\u7ec4\u6307\u9488\u662f\u4e00\u4e2a\u4e8c\u7ea7\u6307\u9488     cout &lt;&lt; a &lt;&lt; endl;      \/\/ a \u662f\u4e00\u4e2a\u6307\u9488\uff0c\u6307\u5411 {1,2,3,4,5,6,7,8,9,10}     cout &lt;&lt; *a &lt;&lt; endl;     \/\/ *a \u4e5f\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u6307\u5411 1 \u7684\u5730\u5740     cout &lt;&lt; **a &lt;&lt; endl;    \/\/ **a \u53d6 1 \u7684\u503c      cout &lt;&lt; a + 1 &lt;&lt; endl;  \/\/ \u6307\u9488\u5411\u540e\u504f\u79fb\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u8fd9\u4e2a\u4f4d\u7f6e\u7684\u957f\u5ea6\u4e3a\u6307\u9488\u6240\u6307\u5bb9\u91cf\u7684\u5927\u5c0f\uff0c\u504f\u79fb\u540e\u6307\u5411 {11,12,13,14,15,16,17,18,19,20}     cout &lt;&lt; *(a + 1) &lt;&lt; endl;  \/\/ \u548c*a \u7684\u539f\u7406\u662f\u4e00\u6837\u7684\uff0c\u6307\u5411 11 \u7684\u5730\u5740     cout &lt;&lt; **(a + 1) &lt;&lt; endl;  \/\/ \u53d6 11 \u7684\u503c      cout &lt;&lt; *a + 1 &lt;&lt; endl;  \/\/ *a \u6307\u5411 1 \u7684\u5730\u5740\uff0c*a + 1, \u6307\u9488\u5411\u540e\u504f\u79fb\u4e00\u4e2a\u4f4d\u7f6e\uff0c*a \u6307\u5411\u7684\u662f int \u578b\u7684\u6570\u636e m, \u5411\u540e\u504f\u79fb sizeof(int)\uff0c\u6307\u5411 2     cout &lt;&lt; *(*a+1) &lt;&lt; endl;  \/\/ \u53d6 2     return 0; } <\/code><\/pre>\n<p><strong>\u4f8b 2: \u7528\u53d8\u91cf a \u7ed9\u51fa\u4e0b\u9762\u7684\u5b9a\u4e49<\/strong><\/p>\n<ol>\n<li>\u4e00\u4e2a\u6574\u578b\u6570\u3002<\/li>\n<li>\u4e00\u4e2a\u6307\u5411\u6574\u578b\u6570\u7684\u6307\u9488\u3002<\/li>\n<li>\u4e00\u4e2a\u6307\u5411\u6307\u9488\u7684\u6307\u9488\uff0c\u5b83\u6307\u5411\u7684\u6307\u9488\u662f\u4e00\u4e2a\u6307\u5411\u4e00\u4e2a\u6574\u578b\u6570<\/li>\n<li>\u4e00\u4e2a\u6709 10 \u4e2a\u6574\u578b\u6570\u7684\u6570\u7ec4<\/li>\n<li>\u4e00\u4e2a\u6709 10 \u4e2a\u6307\u9488\u7684\u6570\u7ec4\uff0c\u8be5\u6307\u9488\u662f\u6307\u5411\u4e00\u4e2a\u6574\u578b\u6570\u7684<\/li>\n<li>\u4e00\u4e2a\u6307\u5411\u6709 10 \u4e2a\u6574\u578b\u6570\u6570\u7ec4\u7684\u6307\u9488<\/li>\n<li>\u4e00\u4e2a\u6307\u5411\u51fd\u6570\u7684\u6307\u9488\uff0c\u8be5\u51fd\u6570\u6709\u4e00\u4e2a\u6574\u578b\u53c2\u6570\u5e76\u8fd4\u56de\u4e00\u4e2a\u6574\u578b\u6570<\/li>\n<li>\u4e00\u4e2a\u6709 10 \u4e2a\u6307\u9488\u7684\u6570\u7ec4\uff0c\u8be5\u6307\u9488\u6307\u5411\u4e00\u4e2a\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u6709\u4e00\u4e2a\u6574\u578b\u53c2\u6570\u5e76\u8fd4\u56de\u4e00\u4e2a\u6574\u578b\u6570<\/li>\n<\/ol>\n<p>\u7b54\u6848:<\/p>\n<pre><code>\/\/ 1 int a; \/\/ 2 int *a; \/\/ 3 int **a; \/\/ 4 int a[10]; \/\/ 5 int *a[10]; \/\/ 6 int (*a)[10]; \/\/ 7 int (*a)(int); \/\/ 8 int (*a[10])(int); <\/code><\/pre>\n<p><strong>\u4f8b 3: \u5199\u51fa\u5982\u4e0b\u7a0b\u5e8f\u7247\u6bb5\u7684\u8f93\u51fa<\/strong><\/p>\n<pre><code>int a[] = {1,2,3,4,5}; int *ptr = (int*)(&amp;a + 1); printf(\"%d %d\", *(a+1), *(ptr - 1)); <\/code><\/pre>\n<p>\u7b54\u6848\uff1a<\/p>\n<pre><code>#include&lt;iostream&gt; #include&lt;cstdio&gt; using namespace std;  int main(int argc, char const *argv[]) {     int a[] = {1,2,3,4,5};     int *ptr = (int*)(&amp;a + 1);      cout &lt;&lt; a &lt;&lt; endl;  \/\/ \u6570\u7ec4\u540d\u7684\u4e00\u4e2a\u6307\u5411\u6570\u7ec4\u5143\u7d20\u7684\u5e38\u91cf\u6307\u9488     cout &lt;&lt; &amp;a &lt;&lt; endl;  \/\/ &amp;a \u5e76\u4e0d\u662f\u4e00\u4e2a\u6307\u5411\u5e38\u91cf\u6307\u9488\u7684\u6307\u9488\uff0c\u800c\u662f\u4e00\u4e2a\u6307\u5411\u6574\u4e2a\u6570\u7ec4\u7684\u6307\u9488      \/\/ \u4ee5\u4e0b\u4e24\u884c\u9a8c\u8bc1\u4ee5\u4e0a\u7684\u89c2\u70b9     cout &lt;&lt; a + 1 &lt;&lt; endl;     cout &lt;&lt; &amp;a + 1 &lt;&lt; endl;      \/\/ \u6240\u4ee5 a + 1 \u6307\u5411 2\uff0c*(a+1) \u4e3a 2     \/\/ &amp;a + 1 \u5e94\u8be5\u6307\u5411 5 \u7684\u4e0b\u4e00\u4e2a\u5143\u7d20\uff0cptr - 1 \u6307\u5411 5     printf(\"%d %d\", *(a+1), *(ptr - 1));     return 0; } <\/code><\/pre>\n<h3>\u8ff7\u9014\u6307\u9488\u548c\u91ce\u6307\u9488<\/h3>\n<p><em>\u8ff7\u9014\u6307\u9488<\/em>: \u6307\u9488\u6307\u5411\u4e00\u4e2a\u5185\u5b58\uff0c\u8fd9\u4e2a\u5185\u5b58\u4f1a\u56de\u6536\u4e86\uff0c\u4f46\u662f\u6ca1\u6709\u5bf9\u8fd9\u4e2a\u6307\u9488\u505a\u5904\u7406\uff0c\u6ca1\u6709\u5c06\u6307\u9488\u8bbe\u4e3a\u7a7a<\/p>\n<p><em>\u91ce\u6307\u9488<\/em>: \u58f0\u660e\u4e86\u4e00\u4e2a\u6307\u9488\uff0c\u6ca1\u6709\u5c06\u6307\u9488\u521d\u59cb\u5316\u3002<\/p>\n<p><strong>\u4f8b 1: \u4e0b\u9762\u7684\u7a0b\u5e8f\u8f93\u51fa\u7ed3\u679c\u662f\u4ec0\u4e48\uff1f<\/strong><\/p>\n<pre><code>#include&lt;iostream&gt; using namespace std;  int main(int argc, char const *argv[]) {     char s1[] = \"hello\";     char s2[] = \"the\";     char s3[] = \"world\";     char* a[] = {s1, s2, s3};     char **pa = a;     pa++;     cout &lt;&lt; *pa &lt;&lt; endl;     return 0; } <\/code><\/pre>\n<p>a \u662f\u4e00\u4e2a\u5e38\u91cf\u6307\u9488\uff0c\u6307\u5411\u6570\u7ec4\u7684\u9996\u5730\u5740\uff0cpa++, \u5411\u540e\u632a\u4e00\u4e2a\u6307\u9488\u5927\u5c0f\uff0c\u6307\u5411 s2, \u8f93\u51fa &#8220;the&#8221;<\/p>\n<h3>\u6307\u9488\u548c\u53e5\u67c4<\/h3>\n<p>\u53e5\u67c4\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u662f\u64cd\u4f5c\u7cfb\u7edf\u5728\u5185\u5b58\u4e2d\u7ef4\u62a4\u7684\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5185\u5b58\u7269\u7406\u5730\u5740\u5217\u8868\u7684\u6574\u6570\u7d22\u5f15\uff0c\u56e0\u4e3a\u64cd\u4f5c\u7cfb\u7edf\u5728\u5185\u5b58\u7ba1\u7406\u65f6\u7ecf\u5e38\u4f1a\u5c06\u5f53\u524d\u7a7a\u95f2\u5bf9\u8c61\u7684\u5185\u5b58\u91ca\u653e\u6389\uff0c\u5f53\u9700\u8981\u8bbf\u95ee\u65f6\u518d\u91cd\u65b0\u63d0\u4ea4\u5230\u7269\u7406\u5185\u5b58\uff0c\u6240\u4ee5\u5bf9\u8c61\u7684\u7269\u7406\u5730\u5740\u662f\u53d8\u5316\u7684\uff0c\u4e0d\u5141\u8bb8\u7a0b\u5e8f\u76f4\u63a5\u901a\u8fc7\u7269\u7406\u5730\u5740\u6765\u8bbf\u95ee\u5bf9\u8c61\u3002 \u7a0b\u5e8f\u5c06\u60f3\u8bbf\u95ee\u7684\u5bf9\u8c61\u7684\u53e5\u67c4\u4f20\u9012\u7ed9\u7cfb\u7edf\uff0c\u7cfb\u7edf\u6839\u636e\u53e5\u67c4\u68c0\u7d22\u81ea\u5df1\u7ef4\u62a4\u7684\u5bf9\u8c61\u5217\u8868\u5c31\u80fd\u77e5\u9053\u7a0b\u5e8f\u60f3\u8bbf\u95ee\u7684\u5bf9\u8c61\u53ca\u5176\u7269\u7406\u5730\u5740\u4e86\u3002<\/p>\n<p><strong>\u53e5\u67c4\u662f\u4e00\u79cd\u6307\u5411\u6307\u9488\u7684\u6307\u9488<\/strong>\u3002 \u6211\u4eec\u77e5\u9053\uff0c\u6240\u8c13\u6307\u9488\u662f\u4e00\u79cd\u5185\u5b58\u5730\u5740\uff0c\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u540e\uff0c\u7ec4\u6210\u8fd9\u4e2a\u7a0b\u5e8f\u7684\u5404\u5bf9\u8c61\u662f\u9a7b\u7559\u5728\u5185\u5b58\u7684\u3002\u5982\u679c\u7b80\u5355\u7684\u7406\u89e3\uff0c\u4f3c\u4e4e\u6211\u4eec\u53ea\u8981\u77e5\u9053\u5185\u5b58\u7684\u9996\u5730\u5740\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u968f\u65f6\u7528\u8fd9\u4e2a\u5730\u5740\u8bbf\u95ee\u5bf9\u8c61\u3002 \u4f46\u662f\uff0c\u5982\u679c\u771f\u7684\u8fd9\u6837\u8ba4\u4e3a\uff0c\u90a3\u4e48\u5c31\u5927\u9519\u7279\u9519\u4e86\uff0c\u6211\u4eec\u77e5\u9053\uff0c\u64cd\u4f5c\u7cfb\u7edf\u662f\u4e00\u4e2a\u4ee5\u865a\u62df\u5185\u5b58\u4e3a\u57fa\u7840\u7684\uff0c\u5b58\u5728\u6362\u9875\u73b0\u8c61\uff0c\u5bf9\u8c61\u5457\u79fb\u52a8\u610f\u5473\u7740\u5b83\u7684\u5730\u5740\u53d8\u5316\u4e86\uff0c\u5982\u679c\u5730\u5740\u603b\u662f\u53d8\u5316\uff0c\u6211\u4eec\u8be5\u600e\u4e48\u5bfb\u627e\u5bf9\u8c61\u5462\uff1f \u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u64cd\u4f5c\u7cfb\u7edf\u4e3a\u5404\u5e94\u7528\u7a0b\u5e8f\u817e\u51fa\u4e00\u4e9b\u5185\u5b58\u5730\u5740\uff0c\u7528\u6765\u4e13\u95e8\u767b\u8bb0\u5404\u5e94\u7528\u5bf9\u8c61\u5728\u5185\u5b58\u4e2d\u7684\u5730\u5740\u53d8\u5316\uff0c\u800c\u767b\u8bb0\u7684\u5730\u5740\u662f\u4e0d\u53d8\u7684\uff0c\u64cd\u4f5c\u7cfb\u7edf\u79fb\u52a8\u5bf9\u8c61\u540e\uff0c\u5c06\u5bf9\u8c61\u7684\u5730\u5740\u544a\u8bc9\u7ed9\u53e5\u67c4\uff0c\u901a\u8fc7\u53e5\u67c4\u5c31\u80fd\u77e5\u9053\u5bf9\u8c61\u5177\u4f53\u7684\u4f4d\u7f6e\u4e86\u3002<\/p>\n<p>\u53e5\u67c4&#8211;&gt; \u767b\u8bb0\u5bf9\u8c61\u5730\u5740\u7684\u5730\u5740 &#8211;&gt; \u5bf9\u8c61\u7684\u5730\u5740 &#8211;&gt; \u5bf9\u8c61<\/p>\n<p>\u7a0b\u5e8f\u6bcf\u6b21\u91cd\u65b0\u542f\u52a8\uff0c\u7cfb\u7edf\u4e0d\u4fdd\u8bc1\u5206\u914d\u7ed9\u8fd9\u4e2a\u7a0b\u5e8f\u7684\u53e5\u67c4\u8fd8\u662f\u539f\u6765\u7684\u53e5\u67c4\uff0c\u5c31\u597d\u6bd4\u53bb\u7535\u5f71\u9662\u6bcf\u6b21\u5356\u7ed9\u6211\u4eec\u7684\u90fd\u4e0d\u662f\u540c\u4e00\u4e2a\u5ea7\u4f4d\u3002<\/p>\n<h3>this \u6307\u9488<\/h3>\n<p>\u5173\u4e8e this \u6307\u9488\uff0c\u6709\u8fd9\u6837\u4e00\u6bb5\u63cf\u8ff0: \u5f53\u4f60\u8fdb\u5165\u4e00\u4e2a\u623f\u5b50\u540e\uff0c\u4f60\u53ef\u4ee5\u770b\u89c1\u684c\u5b50\uff0c\u6905\u5b50\uff0c\u7b49\uff0c\u4f46\u662f\u4f60\u770b\u4e0d\u5230\u5168\u8c8c\u4e86<\/p>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u7c7b\u7684\u5b9e\u4f8b\u6765\u8bf4\uff0c\u4f60\u53ef\u4ee5\u770b\u5230\u6210\u5458\u51fd\u6570\uff0c\u6210\u5458\u53d8\u91cf\uff0c\u4f46\u662f\u5b9e\u4f8b\u672c\u8eab\u5462\uff1f this \u6307\u9488\u5c31\u662f\u8fd9\u6837\u4e00\u4e2a\u6307\u9488\uff0c\u65f6\u65f6\u523b\u523b\u6307\u5411\u5b9e\u4f8b\u672c\u8eab<\/p>\n<ol>\n<li>this \u6307\u9488\u672c\u8d28\u662f\u4e00\u4e2a\u51fd\u6570\u53c2\u6570\uff0c\u53ea\u662f\u7f16\u8bd1\u5668\u9690\u85cf\u8d77\u6765\u7684\uff0c\u8bed\u6cd5\u5c42\u9762\u7684\u53c2\u6570\uff0c\u5b9e\u9645\u4e0a\uff0c\u6210\u5458\u51fd\u6570\u9ed8\u8ba4\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a T* const this<\/li>\n<li>this \u5728\u6210\u5458\u51fd\u6570\u7684\u5f00\u59cb\u524d\u6784\u9020\uff0c\u7ed3\u675f\u540e\u6e05\u9664\u3002 <\/li>\n<\/ol>\n<p><code>a.func(10);<\/code> \u4f1a\u88ab\u7f16\u8bd1\u5668\u7f16\u8bd1\u6210 <code>A::func(&amp;a, 10);<\/code>, \u770b\u8d77\u6765\u548c\u9759\u6001\u51fd\u6570\u6ca1\u533a\u522b\uff0c\u4e0d\u8fc7\uff0c\u533a\u522b\u8fd8\u662f\u6709\u7684\u3002 \u7f16\u8bd1\u5668\u901a\u5e38\u4f1a\u5bf9 this \u6307\u9488\u505a\u4e00\u4e9b\u4f18\u5316\uff0cthis \u6307\u9488\u7684\u4f20\u9012\u6548\u7387\u6bd4\u8f83\u9ad8\uff0c\u5982 VC \u901a\u5e38\u662f\u901a\u8fc7 ecx \u5bc4\u5b58\u5668\u4f20\u9012\u3002<\/p>\n<ol>\n<li>this \u6307\u9488\u5e76\u4e0d\u5360\u7528\u5bf9\u8c61\u7a7a\u95f4\uff0cthis \u76f8\u5f53\u4e8e\u975e\u9759\u6001\u6210\u5458\u51fd\u6570\u7684\u4e00\u4e2a\u9690\u542b\u7684\u53c2\u6570\uff0c\u4e0d\u5360\u5bf9\u8c61\u7a7a\u95f4\u3002<\/li>\n<li>this \u6307\u9488\u5b58\u653e\u5728\u4f55\u5904\uff1f this \u6307\u9488\u4f1a\u56e0\u7f16\u8bd1\u5668\u4e0d\u540c\u800c\u6709\u4e0d\u540c\u7684\u4f4d\u7f6e\uff0c\u53ef\u80fd\u662f\u5806\uff0c\u6808\uff0c\u4e5f\u53ef\u80fd\u662f\u5bc4\u5b58\u5668\u3002<\/li>\n<li>this \u6307\u9488\u662f\u5982\u4f55\u4f20\u9012\u7ed9\u7c7b\u4e2d\u7684\u51fd\u6570\u7684\uff1f \u5927\u591a\u6570\u7f16\u8bd1\u5668\u662f\u901a\u8fc7 ecx \u5bc4\u5b58\u5668\u4f20\u9012 this \u6307\u9488\uff0c\u4e8b\u5b9e\u4e0a\uff0c\u8fd9\u4e5f\u662f\u4e00\u4e2a\u6f5c\u89c4\u5219\uff0c\u4e00\u534a\u6765\u8bf4\uff0c\u4e0d\u540c\u7f16\u8bd1\u5668\u90fd\u4f1a\u9075\u4ece\u4e00\u81f4\u7684\u4f20\u53c2\u539f\u5219\uff0c\u5426\u5219\u4e0d\u540c\u7684\u7f16\u8bd1\u5668\u4ea7\u751f\u7684 obj \u5c31\u65e0\u6cd5\u5339\u914d\u4e86<\/li>\n<li>\u6211\u4eec\u53ea\u6709\u83b7\u5f97\u4e00\u4e2a\u5bf9\u8c61\u540e\uff0c\u624d\u80fd\u901a\u8fc7\u5bf9\u8c61\u4f7f\u7528 this \u6307\u9488\uff0c\u5982\u679c\u6211\u4eec\u77e5\u9053\u5bf9\u8c61 this \u7684\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u5417\uff1f<\/li>\n<\/ol>\n<p>this \u6307\u9488\u53ea\u6709\u5728\u6210\u5458\u51fd\u6570\u4e2d\u624d\u6709\u5b9a\u4e49\u3002 \u56e0\u6b64\uff0c\u4f60\u83b7\u5f97\u4e00\u4e2a\u5bf9\u8c61\u540e\uff0c\u4e5f\u4e0d\u80fd\u901a\u8fc7\u5bf9\u8c61\u4f7f\u7528 this \u6307\u9488\uff0c\u53ea\u6709\u5728\u6210\u5458\u51fd\u6570\u5185\u624d\u6709 this<\/p>\n<p> <img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2021\/03\/20210311_604a627ef271a.gif\" alt=\"\u6211\u6574\u7406\u4e86\u8fd9\u7bc7\u6307\u9488\u7684\u77e5\u8bc6\u70b9\uff0c\u60f3\u5fc5\u5bf9\u4f60\u6709\u7528\" \/>  <\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5373546\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wutiantong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6240\u4ee5\u4e2d\u6587\u7f16\u7a0b\u6280\u672f\u793e\u533a\u4e00\u76f4\u5b58\u5728\u7684\u4e00\u4e2a\u4e25\u91cd\u95ee\u9898\u662f\uff0c\u65e0\u8bba\u662f\u5728\u4e66\u672c\u4e0a\u8fd8\u662f\u8bba\u575b\u535a\u5ba2\u4e0a\uff0c\u5230\u5904\u90fd\u53ef\u80fd\u5145\u65a5\u7740\u4f3c\u662f\u800c\u975e\uff0c\u6df7\u6dc6\u6982\u5ff5\uff0c\u4e0d\u591f\u7cbe\u786e\u7684\u8868\u8fbe\u3002\u5c31\u4ee5\u8fd9\u7bc7\u6587\u7ae0\u6765\u8bf4\uff1a<\/p>\n<p>1. \u6307\u9488\u53ef\u4ee5\u6307\u5411\u7a7a\u3002<br \/>2. \u6307\u9488\u5e94\u8be5\u603b\u662f\u8981\u88ab\u6d4b\u8bd5\uff0c\u9632\u6b62\u5176\u4e3a\u7a7a<br \/>3. \u7f16\u8bd1\u5668\u603b\u662f\u4e3a\u51fd\u6570\u7684\u6bcf\u4e2a\u53c2\u6570\u5236\u4f5c\u4e00\u4e2a\u4e34\u65f6\u526f\u672c\u3002<br \/>4. p \u7533\u8bf7\u4e86\u4e00\u4e2a\u65b0\u7684\u5185\u5b58\u7a7a\u95f4\u3002\u3002\u3002\u5e76\u4e14 p \u7533\u8bf7\u7684\u5185\u5b58\u3002\u3002\u3002<br \/>5. \u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u628a\u7533\u8bf7\u597d\u7684\u5185\u5b58\u8fd4\u56de\u3002<br \/>6. str \u91cc\u5b58\u7684\u5730\u5740\u662f\u51fd\u6570 strA \u6808\u5e27\u91cc&#8221;hello world&#8221;\u7684\u9996\u5730\u5740<br \/>7. \uff08\u8fd9\u91cc\u6574\u6bb5\u90fd\u662f\u9519\u8bef\u7684\uff0c\u5305\u62ec\u4ee3\u7801\uff09 char str[] \u5206\u914d\u7684\u662f\u4e00\u4e2a\u5c40\u90e8\u6570\u7ec4\uff0cchar* str \u5206\u914d\u7684\u662f\u4e00\u4e2a\u6307\u9488\u904d\u5386 \u3002\u3002\u3002 \u6307\u9488\u53d8\u91cf\u662f\u5168\u5c40\u53d8\u91cf\uff0c\u5b83\u5bf9\u5e94\u7684\u662f\u5185\u5b58\u4e2d\u7684\u5168\u5c40\u533a\u57df\u3002<br \/>8. \uff08\u53c8\u5728\u8bb2\u9519\u8bef\u7684\u4e1c\u897f\uff09\u5f3a\u5236\u628a a \u5730\u5740\u5185\u5bb9\u770b\u6210\u4e00\u4e2a B \u7c7b\u7684\u5bf9\u8c61\uff0cpb \u6307\u5411\u7684\u662f a \u7c7b\u7684\u5185\u5b58\u7a7a\u95f4, \u628a a \u7c7b\u7a7a\u95f4\u6309\u7167 B \u7c7b\u7684\u7ed3\u6784\u6765\u89e3\u8bfb\u3002<br \/>9. *a \u4e5f\u662f\u4e00\u4e2a\u6307\u9488\uff0c\u6307\u5411 1 \u7684\u5730\u5740<br \/>10. \u6570\u7ec4\u540d\u7684\u4e00\u4e2a\u6307\u5411\u6570\u7ec4\u5143\u7d20\u7684\u5e38\u91cf\u6307\u9488\u3002\u3002\u3002&amp;a \u5e76\u4e0d\u662f\u4e00\u4e2a\u6307\u5411\u5e38\u91cf\u6307\u9488\u7684\u6307\u9488                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5373547\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : bfdh <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6307\u9488\u771f\u7684\u662f\u8d8a\u89e3\u91ca\u8d8a\u4e71\uff0c\u6307\u9488\u5c31\u662f\u4e00\u4e2a\u5730\u5740\u800c\u5df2\uff0c\u90a3\u4e9b\u6240\u8c13\u7684\u6307\u9488\u7c7b\u578b\u4e0d\u8fc7\u662f\u89e3\u8bfb\u6307\u9488\u6307\u5411\u5185\u5bb9\u7684\u65b9\u6cd5\u800c\u5df2\uff0c\u90fd\u4e0d\u5f71\u54cd\u6307\u9488\u7684\u672c\u8d28\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5373548\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jones2000 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @bfdh &#8220;\u6307\u9488\u771f\u7684\u662f\u8d8a\u89e3\u91ca\u8d8a\u4e71&#8221; \u8fd9\u6837\u624d\u80fd\u6709\u7a81\u51fa\u6709\u96be\u5ea6,\u597d\u5ffd\u60a0, 1 \u53e5\u8bdd\u5c31\u89e3\u91ca\u6e05\u695a\u4e86, \u540e\u9762\u8fd9\u4e48\u5356\u6587\u7ae0\u548c\u8bfe\u7a0b\u5462.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5373549\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : yiouejv <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u53c8\u4e0d\u662f\u57f9\u8bad\u673a\u6784\uff0c\u81ea\u5df1\u5b66\u4e60\u5206\u4eab\u800c\u5df2\u3002\u4e0d\u5356\u8bfe\u54c8                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u6574\u7406\u4e86\u8fd9\u7bc7\u6307\u9488\u7684\u77e5\u8bc6\u70b9\uff0c\u60f3\u5fc5\u5bf9\u4f60&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/384578"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=384578"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/384578\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=384578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=384578"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=384578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}