{"id":65954,"date":"2026-01-25T23:48:36","date_gmt":"2026-01-25T15:48:36","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/65954.html"},"modified":"2026-01-25T23:48:36","modified_gmt":"2026-01-25T15:48:36","slug":"c%e5%91%bd%e5%90%8d%e7%a9%ba%e9%97%b4%ef%bc%9a%e9%ab%98%e6%95%88%e8%a7%a3%e5%86%b3%e4%bb%a3%e7%a0%81%e5%86%b2%e7%aa%81","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/65954.html","title":{"rendered":"C++\u547d\u540d\u7a7a\u95f4\uff1a\u9ad8\u6548\u89e3\u51b3\u4ee3\u7801\u51b2\u7a81"},"content":{"rendered":"<p>\u4e0b\u9762\u8be6\u7ec6\u8bb2\u89e3C&#043;&#043;\u4e2d\u7684\u547d\u540d\u7a7a\u95f4&#xff08;namespace&#xff09;\u6982\u5ff5&#xff1a;<\/p>\n<hr \/>\n<h4>1. \u547d\u540d\u7a7a\u95f4\u7684\u4f5c\u7528<\/h4>\n<p>\u547d\u540d\u7a7a\u95f4\u7528\u4e8e\u89e3\u51b3\u547d\u540d\u51b2\u7a81\u95ee\u9898\u3002\u5728\u5927\u578b\u9879\u76ee\u4e2d&#xff0c;\u4e0d\u540c\u5e93\u53ef\u80fd\u5b9a\u4e49\u540c\u540d\u53d8\u91cf\/\u51fd\u6570&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<p>\/\/ \u5e93A<br \/>\nvoid print() { \/*&#8230;*\/ }<\/p>\n<p>\/\/ \u5e93B<br \/>\nvoid print() { \/*&#8230;*\/ } \/\/ \u7f16\u8bd1\u9519\u8bef&#xff1a;\u91cd\u5b9a\u4e49<\/p>\n<p>\u901a\u8fc7\u547d\u540d\u7a7a\u95f4\u9694\u79bb&#xff1a;<\/p>\n<p>namespace LibA {<br \/>\n    void print() { \/*&#8230;*\/ }<br \/>\n}<\/p>\n<p>namespace LibB {<br \/>\n    void print() { \/*&#8230;*\/ }<br \/>\n}<\/p>\n<hr \/>\n<h4>2. \u5b9a\u4e49\u547d\u540d\u7a7a\u95f4<\/h4>\n<p>\u8bed\u6cd5&#xff1a;<\/p>\n<p>namespace \u540d\u79f0 {<br \/>\n    \/\/ \u53d8\u91cf\u3001\u51fd\u6570\u3001\u7c7b\u7b49<br \/>\n}<\/p>\n<p>\u793a\u4f8b&#xff1a;<\/p>\n<p>namespace Math {<br \/>\n    const double PI &#061; 3.14159;<br \/>\n    double square(double x) { return x * x; }<br \/>\n}<\/p>\n<hr \/>\n<h4>3. \u4f7f\u7528\u547d\u540d\u7a7a\u95f4<\/h4>\n<h5>(1) \u4f5c\u7528\u57df\u89e3\u6790\u7b26::<\/h5>\n<p>double circle_area &#061; Math::PI * Math::square(r);<\/p>\n<h5>(2) using\u58f0\u660e&#xff08;\u5c40\u90e8\u5f15\u5165&#xff09;<\/h5>\n<p>int main() {<br \/>\n    using Math::PI; \/\/ \u4ec5\u5f15\u5165PI<br \/>\n    double area &#061; PI * r * r;<br \/>\n}<\/p>\n<h5>(3) using namespace&#xff08;\u5168\u5c40\u5f15\u5165-\u614e\u7528&#xff01;&#xff09;<\/h5>\n<p>using namespace Math; \/\/ \u5f15\u5165\u6574\u4e2a\u547d\u540d\u7a7a\u95f4<br \/>\ndouble area &#061; PI * square(r);<\/p>\n<p>\u6ce8\u610f&#xff1a;\u5728\u5934\u6587\u4ef6\u4e2d\u907f\u514d\u4f7f\u7528using namespace&#xff0c;\u4ee5\u514d\u6c61\u67d3\u5168\u5c40\u4f5c\u7528\u57df\u3002<\/p>\n<hr \/>\n<h4>4. \u5d4c\u5957\u547d\u540d\u7a7a\u95f4<\/h4>\n<p>\u652f\u6301\u591a\u5c42\u5d4c\u5957&#xff1a;<\/p>\n<p>namespace Project {<br \/>\n    namespace IO {<br \/>\n        void save() { \/*&#8230;*\/ }<br \/>\n    }<br \/>\n}<br \/>\n\/\/ \u4f7f\u7528<br \/>\nProject::IO::save();<\/p>\n<hr \/>\n<h4>5. \u533f\u540d\u547d\u540d\u7a7a\u95f4<\/h4>\n<p>\u7528\u4e8e\u9650\u5236\u4f5c\u7528\u57df\u81f3\u5f53\u524d\u6587\u4ef6&#xff08;\u7c7b\u4f3cstatic&#xff09;&#xff1a;<\/p>\n<p>namespace { \/\/ \u4ec5\u5f53\u524d.cpp\u6587\u4ef6\u53ef\u89c1<br \/>\n    int local_var &#061; 42;<br \/>\n}<\/p>\n<hr \/>\n<h4>6. \u5b9e\u9645\u5de5\u7a0b\u5efa\u8bae<\/h4>\n<ul>\n<li>\u907f\u514d\u5168\u5c40using namespace&#xff1a;\u5c24\u5176\u5728\u5934\u6587\u4ef6\u4e2d&#xff0c;\u6613\u5f15\u53d1\u51b2\u7a81\u3002<\/li>\n<li>\u5408\u7406\u547d\u540d&#xff1a;\u5982MyProject::Utilities\u4ee3\u66ff\u6cdb\u7528\u540d\u3002<\/li>\n<li>C&#043;&#043;17\u5d4c\u5957\u7b80\u5316&#xff1a; namespace Project::IO { \/\/ \u76f4\u63a5\u5d4c\u5957<br \/>\n    void save() { \/*&#8230;*\/ }<br \/>\n}<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u4ee3\u7801\u793a\u4f8b<\/h4>\n<p>#include &lt;iostream&gt;<\/p>\n<p>namespace Geometry {<br \/>\n    const double PI &#061; 3.1415926;<br \/>\n    double area(double radius) {<br \/>\n        return PI * radius * radius;<br \/>\n    }<br \/>\n}<\/p>\n<p>int main() {<br \/>\n    double r &#061; 5.0;<br \/>\n    std::cout &lt;&lt; &#034;\u5706\u9762\u79ef: &#034; &lt;&lt; Geometry::area(r) &lt;&lt; std::endl;<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\u8f93\u51fa&#xff1a;<\/p>\n<p>\u5706\u9762\u79ef: 78.5398<\/p>\n<p>\u901a\u8fc7\u547d\u540d\u7a7a\u95f4\u7ec4\u7ec7\u4ee3\u7801&#xff0c;\u53ef\u663e\u8457\u63d0\u5347\u53ef\u7ef4\u62a4\u6027\u548c\u534f\u4f5c\u6548\u7387&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u8be6\u7ec6\u8bb2\u89e3C\u4e2d\u7684\u547d\u540d\u7a7a\u95f4&#xff08;namespace&#xff09;\u6982\u5ff5&#xff1a; 1. \u547d\u540d\u7a7a\u95f4\u7684\u4f5c\u7528<br \/>\n\u547d\u540d\u7a7a\u95f4\u7528\u4e8e\u89e3\u51b3\u547d\u540d\u51b2\u7a81\u95ee\u9898\u3002\u5728\u5927\u578b\u9879\u76ee\u4e2d&#xff0c;\u4e0d\u540c\u5e93\u53ef\u80fd\u5b9a\u4e49\u540c\u540d\u53d8\u91cf\/\u51fd\u6570&#xff0c;\u4f8b\u5982&#xff1a;<br \/>\n\/\/ \u5e93A<br \/>\nvoid print() { \/*&#8230;*\/ }\/\/ \u5e93B<br \/>\nvoid print() { \/*&#8230;*\/ } \/\/ \u7f16\u8bd1\u9519\u8bef&#xff1a;\u91cd\u5b9a\u4e49\u901a\u8fc7\u547d\u540d\u7a7a\u95f4\u9694\u79bb&#xff1a;<br \/>\nnamespace LibA {voi<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,190],"topic":[],"class_list":["post-65954","post","type-post","status-publish","format-standard","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++\u547d\u540d\u7a7a\u95f4\uff1a\u9ad8\u6548\u89e3\u51b3\u4ee3\u7801\u51b2\u7a81 - \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\/65954.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++\u547d\u540d\u7a7a\u95f4\uff1a\u9ad8\u6548\u89e3\u51b3\u4ee3\u7801\u51b2\u7a81 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e0b\u9762\u8be6\u7ec6\u8bb2\u89e3C\u4e2d\u7684\u547d\u540d\u7a7a\u95f4&#xff08;namespace&#xff09;\u6982\u5ff5&#xff1a; 1. \u547d\u540d\u7a7a\u95f4\u7684\u4f5c\u7528 \u547d\u540d\u7a7a\u95f4\u7528\u4e8e\u89e3\u51b3\u547d\u540d\u51b2\u7a81\u95ee\u9898\u3002\u5728\u5927\u578b\u9879\u76ee\u4e2d&#xff0c;\u4e0d\u540c\u5e93\u53ef\u80fd\u5b9a\u4e49\u540c\u540d\u53d8\u91cf\/\u51fd\u6570&#xff0c;\u4f8b\u5982&#xff1a; \/\/ \u5e93A void print() { \/*...*\/ }\/\/ \u5e93B void print() { \/*...*\/ } \/\/ \u7f16\u8bd1\u9519\u8bef&#xff1a;\u91cd\u5b9a\u4e49\u901a\u8fc7\u547d\u540d\u7a7a\u95f4\u9694\u79bb&#xff1a; namespace LibA {voi\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/65954.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-25T15:48:36+00:00\" \/>\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=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/65954.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/65954.html\",\"name\":\"C++\u547d\u540d\u7a7a\u95f4\uff1a\u9ad8\u6548\u89e3\u51b3\u4ee3\u7801\u51b2\u7a81 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-25T15:48:36+00:00\",\"dateModified\":\"2026-01-25T15:48:36+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/65954.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/65954.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/65954.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++\u547d\u540d\u7a7a\u95f4\uff1a\u9ad8\u6548\u89e3\u51b3\u4ee3\u7801\u51b2\u7a81\"}]},{\"@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++\u547d\u540d\u7a7a\u95f4\uff1a\u9ad8\u6548\u89e3\u51b3\u4ee3\u7801\u51b2\u7a81 - \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\/65954.html","og_locale":"zh_CN","og_type":"article","og_title":"C++\u547d\u540d\u7a7a\u95f4\uff1a\u9ad8\u6548\u89e3\u51b3\u4ee3\u7801\u51b2\u7a81 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e0b\u9762\u8be6\u7ec6\u8bb2\u89e3C\u4e2d\u7684\u547d\u540d\u7a7a\u95f4&#xff08;namespace&#xff09;\u6982\u5ff5&#xff1a; 1. \u547d\u540d\u7a7a\u95f4\u7684\u4f5c\u7528 \u547d\u540d\u7a7a\u95f4\u7528\u4e8e\u89e3\u51b3\u547d\u540d\u51b2\u7a81\u95ee\u9898\u3002\u5728\u5927\u578b\u9879\u76ee\u4e2d&#xff0c;\u4e0d\u540c\u5e93\u53ef\u80fd\u5b9a\u4e49\u540c\u540d\u53d8\u91cf\/\u51fd\u6570&#xff0c;\u4f8b\u5982&#xff1a; \/\/ \u5e93A void print() { \/*...*\/ }\/\/ \u5e93B void print() { \/*...*\/ } \/\/ \u7f16\u8bd1\u9519\u8bef&#xff1a;\u91cd\u5b9a\u4e49\u901a\u8fc7\u547d\u540d\u7a7a\u95f4\u9694\u79bb&#xff1a; namespace LibA {voi","og_url":"https:\/\/www.wsisp.com\/helps\/65954.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-25T15:48:36+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/65954.html","url":"https:\/\/www.wsisp.com\/helps\/65954.html","name":"C++\u547d\u540d\u7a7a\u95f4\uff1a\u9ad8\u6548\u89e3\u51b3\u4ee3\u7801\u51b2\u7a81 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-25T15:48:36+00:00","dateModified":"2026-01-25T15:48:36+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/65954.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/65954.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/65954.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C++\u547d\u540d\u7a7a\u95f4\uff1a\u9ad8\u6548\u89e3\u51b3\u4ee3\u7801\u51b2\u7a81"}]},{"@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\/65954","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=65954"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/65954\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=65954"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=65954"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=65954"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=65954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}