{"id":51,"date":"2007-10-13T13:40:06","date_gmt":"2007-10-13T17:40:06","guid":{"rendered":"http:\/\/www.prglab.com\/blog\/p\/51"},"modified":"2007-10-13T13:40:06","modified_gmt":"2007-10-13T17:40:06","slug":"pointer-vs-reference-functions","status":"publish","type":"post","link":"https:\/\/www.prglab.com\/blog\/p\/51","title":{"rendered":"\u4ee5\u6307\u9488\u6216reference\u4e3a\u53c2\u6570\u7684C++\u51fd\u6570\u5b9a\u4e49\u4e0e\u8c03\u7528\u5bf9\u7167\u8868"},"content":{"rendered":"<p>\u521d\u5b66\u8005\u4e0d\u6613\u5efa\u7acb\u6e05\u6670\u7684\u6307\u9488\u548creference\u6982\u5ff5\uff0c\u603b\u7ed3\u8fd9\u4e2a\u8868\u4ee5\u4f9b\u5feb\u901f\u53c2\u8003\uff1a<\/p>\n<p>\u5047\u8bbe\u6709\u5bf9\u8c61\u5b9a\u4e49:<br \/>\nMyObjectType obj1;<\/p>\n<p><span style=\"color: blue\">1. \u503c\u4f20\u9012:<\/span><br \/>\n\u5982\u679c\u51fd\u6570\u5b9a\u4e49\u4e3a:<br \/>\nvoid myFunction( MyObjectType obj);<\/p>\n<p>\u51fd\u6570\u8c03\u7528:<br \/>\nmyFunction(obj); <span style=\"color: green\">\/\/\u51fd\u6570\u4ee5\u5916\u5bf9\u8c61obj\u7684\u503c<strong>\u4e0d\u4f1a<\/strong> \u6539\u53d8<\/span><\/p>\n<p><span style=\"color: blue\">2. reference\u4f20\u9012:<\/span><br \/>\n\u5982\u679c\u51fd\u6570\u5b9a\u4e49\u4e3a:<br \/>\nvoid myFunction( MyObjectType &amp;obj);<\/p>\n<p>\u51fd\u6570\u8c03\u7528:<br \/>\nmyFunction(obj); <span style=\"color: green\">\/\/\u51fd\u6570\u4ee5\u5916\u5bf9\u8c61obj\u7684\u503c<strong>\u4f1a<\/strong> \u6539\u53d8<\/span><\/p>\n<p><span style=\"color: blue\">3. \u6307\u9488\u4f20\u9012:<\/span><br \/>\n\u5982\u679c\u51fd\u6570\u5b9a\u4e49\u4e3a:<br \/>\nvoid myFunction( MyObjectType *obj);<\/p>\n<p>\u51fd\u6570\u8c03\u7528:<br \/>\nmyFunction(&amp;obj); <span style=\"color: green\">\/\/\u9700\u8981dereference(&amp;), \u51fd\u6570\u4ee5\u5916\u5bf9\u8c61obj\u7684\u503c<strong>\u4f1a<\/strong> \u6539\u53d8<\/span><\/p>\n<p>\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8eC++\u6307\u9488\u7684\u6982\u5ff5\u8bf7\u9605\u8bfb<a href=\"http:\/\/www.prglab.com\/cms\/pages\/c-tutorial\/advanced-data\/pointers.php\" target=\"_blank\">C++\u57fa\u7840\u6559\u7a0b\u6307\u9488\u7bc7<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u521d\u5b66\u8005\u4e0d\u6613\u5efa\u7acb\u6e05\u6670\u7684\u6307\u9488\u548creference\u6982\u5ff5\uff0c\u603b\u7ed3\u8fd9\u4e2a\u8868\u4ee5\u4f9b\u5feb\u901f\u53c2\u8003\uff1a \u5047\u8bbe\u6709\u5bf9\u8c61\u5b9a\u4e49: MyObjectType obj1; 1. \u503c\u4f20\u9012: \u5982\u679c\u51fd\u6570\u5b9a\u4e49\u4e3a: void myFunction( MyObjectType obj); \u51fd\u6570\u8c03\u7528: myFunction(obj); \/\/\u51fd\u6570\u4ee5\u5916\u5bf9\u8c61obj\u7684\u503c\u4e0d\u4f1a \u6539\u53d8 2. reference\u4f20\u9012: \u5982\u679c\u51fd\u6570\u5b9a\u4e49\u4e3a: void myFunction( MyObjectType &amp;obj); \u51fd\u6570\u8c03\u7528: myFunction(obj); \/\/\u51fd\u6570\u4ee5\u5916\u5bf9\u8c61obj\u7684\u503c\u4f1a \u6539\u53d8 3. \u6307\u9488\u4f20\u9012: \u5982\u679c\u51fd\u6570\u5b9a\u4e49\u4e3a: void myFunction( MyObjectType *obj); \u51fd\u6570\u8c03\u7528: myFunction(&amp;obj); \/\/\u9700\u8981dereference(&amp;), \u51fd\u6570\u4ee5\u5916\u5bf9\u8c61obj\u7684\u503c\u4f1a \u6539\u53d8 \u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8eC++\u6307\u9488\u7684\u6982\u5ff5\u8bf7\u9605\u8bfbC++\u57fa\u7840\u6559\u7a0b\u6307\u9488\u7bc7<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/posts\/51"}],"collection":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/comments?post=51"}],"version-history":[{"count":0,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/posts\/51\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/media?parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/categories?post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.prglab.com\/blog\/wp-json\/wp\/v2\/tags?post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}