{"id":3016,"date":"2020-12-29T14:14:35","date_gmt":"2020-12-29T06:14:35","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=3016"},"modified":"2020-12-29T17:38:53","modified_gmt":"2020-12-29T09:38:53","slug":"%e6%a8%a1%e6%9d%bf%e7%9a%84%e7%89%b9%e5%8c%96%e4%b8%8e%e5%81%8f%e7%89%b9%e5%8c%96","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=3016","title":{"rendered":"\u6a21\u677f\u7684\u7279\u5316\u4e0e\u504f\u7279\u5316"},"content":{"rendered":"\n<p>\u7c7b\u6a21\u677f\u7279\u5316\u8bed\u6cd5\u4e3a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>template&lt;typename T1, typename T2, typename T3>\nstruct TBase\n{\n}\n\n\/\/ \u504f\u7279\u5316\uff1aT1\/T2\/ST\ntemplate&lt;typename T1, typename T2>\nstruct TBase&lt;T1, T2, specializationsType>\n{\n}\n\n\/\/ \u504f\u7279\u5316\uff1aT1\/ST\/T3\ntemplate&lt;typename T1, typename T3>\nstruct TBase&lt;T1, specializationsType, T3>\n{\n}\n\n\/\/ \u5728\u58f0\u660e\u65f6\uff0c\u9700\u8981\u5728\u504f\u7279\u5316template&lt;>\u4e2d\uff0c\u628a\u504f\u7279\u5316\u7684\u7c7b\u53bb\u6389<\/code><\/pre>\n\n\n\n<p>\u51fd\u6570\u4e0d\u5b58\u5728\u504f\u7279\u5316\uff0c\u53ea\u80fd\u5168\u7279\u5316\uff0c\u4ee5\u4e0b\u4e3a\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h>\n\ntemplate&lt;typename T1, typename T2>\nint foo(T1 a, T2 b)\n{\n    return 0;\n}\n\ntemplate&lt;>\nint foo&lt;int, int>(int a, int b) \/\/ A\n{\n    return 100;\n}\n\ntemplate&lt;typename T1, typename T2>\nint foo(int a, int b) \/\/ B\n{\n    return 300;\n}\n\n\/\/ \u5176\u4e2dA\u548cB\u4e3a\u4e24\u4e2a\u4e0d\u540c\u7684\u51fd\u6570\u4f53\uff0c\u6240\u4ee5\uff0c\u4e0b\u9762\u8c03\u7528\uff0c\u7b2c1\u4e2a\u901a\u8fc7\uff0c\u7b2c2\u4e2a\u89e6\u53d1\u7f16\u8bd1\u5668\u5f02\u5e38\nfoo(100, 100);\nfoo&lt;int,int>(100,100);\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7c7b\u6a21\u677f\u7279\u5316\u8bed\u6cd5\u4e3a \u51fd\u6570\u4e0d\u5b58\u5728\u504f\u7279\u5316\uff0c\u53ea\u80fd\u5168\u7279\u5316\uff0c\u4ee5\u4e0b\u4e3a\u4f8b\u5b50\uff1a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/3016"}],"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=3016"}],"version-history":[{"count":5,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/3016\/revisions"}],"predecessor-version":[{"id":3022,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/3016\/revisions\/3022"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}