{"id":1598,"date":"2020-04-05T14:59:20","date_gmt":"2020-04-05T06:59:20","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=1598"},"modified":"2021-01-19T18:40:57","modified_gmt":"2021-01-19T10:40:57","slug":"c%e6%a0%87%e5%87%86%e5%ad%a6%e4%b9%a0","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=1598","title":{"rendered":"[c++]decltype"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\nclass student\n{\nprivate:\n\tint age;\npublic:\n\tvoid setAge(int age)\n\t{\n\t\tthis->age = age;\n\t}\n};\n\nstudent&amp; CreateStudent()\n{\n\tstatic student stdobj;\n\treturn stdobj;\n}\n\n\nstudent&amp; CreateStudent2()\n{\n\tstatic student stdobj;\n\treturn stdobj;\n}\n\nint main()\n{\n\tdecltype(CreateStudent()) xiaoming1 = CreateStudent(); \/\/ xiaoming\u4e3a student&amp; \u7c7b\u578b\n\tdecltype(CreateStudent2()) xiaoming2 = CreateStudent2(); \/\/ xiaoming\u4e3a student&amp; \u7c7b\u578b\n\tauto zhangsan = CreateStudent(); \/\/ zhangsan \u4e3a student \u7c7b\u578b\n\tauto lisi = CreateStudent2(); \/\/ lisi \u4e3a student \u7c7b\u578b\n}\n<\/code><\/pre>\n\n\n\n<p>decltype \u4e3a\u7f16\u8bd1\u5668\u63a8\u65ad\u5173\u952e\u5b57\uff0c\u5176\u4ee3\u7801\u53ea\u63a8\u65ad\u4e0d\u6267\u884c<br>auto \u4e3a\u7f16\u8bd1\u5668\u5e2e\u7a0b\u5e8f\u5458\u624b\u5de5\u586b\u5199\u5173\u952e\u5b57\uff0c\u5176\u4ee3\u7801\u5b8c\u6574\u6267\u884c<\/p>\n\n\n\n<p>decltype \u63a8\u65ad\u5176\u5b8c\u6574\u7c7b\u578b<br>auto \u4f1a\u5265\u79bb\u6389&amp;(\u5f15\u7528)\u64cd\u4f5c\u7b26\uff0c\u5373\u82e5 a\u4e3a int&amp; \u578b\uff0c\u5219\u7528auto\u4f1a\u83b7\u5f97int<\/p>\n\n\n\n<p>\u6240\u4ee5\u53ef\u4ee5\u5199\u51fa\u7c7b\u4f3c\u4e8e<br>auto p = new decltype(CreateStudent3()); \u7684\u8bed\u6cd5<\/p>\n","protected":false},"excerpt":{"rendered":"<p>decltype \u4e3a\u7f16\u8bd1\u5668\u63a8\u65ad\u5173\u952e\u5b57\uff0c\u5176\u4ee3\u7801\u53ea\u63a8\u65ad\u4e0d\u6267\u884cauto \u4e3a\u7f16\u8bd1\u5668\u5e2e\u7a0b\u5e8f\u5458\u624b\u5de5\u586b\u5199\u5173\u952e\u5b57\uff0c\u5176\u4ee3\u7801\u5b8c\u6574\u6267 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[20],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1598"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1598"}],"version-history":[{"count":4,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1598\/revisions"}],"predecessor-version":[{"id":1603,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1598\/revisions\/1603"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}