From 15dd3a0b69a5f06d691d6b838d48e12c014ff6f8 Mon Sep 17 00:00:00 2001 From: Ultcrt <44793627+Ultcrt@users.noreply.github.com> Date: Mon, 25 Dec 2023 14:44:20 +0800 Subject: [PATCH] =?UTF-8?q?Update=20Posts=20=E2=80=9C2023-10-08-c-?= =?UTF-8?q?=E5=BC=80=E5=8F=91=E6=97=B6=E9=81=87=E5=88=B0=E7=9A=84=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E9=9A=BE=E4=BB=A5=E6=8E=92=E6=9F=A5=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...6\222\346\237\245\347\232\204\351\224\231\350\257\257.md" | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git "a/_posts/2023-10-08-c-\345\274\200\345\217\221\346\227\266\351\201\207\345\210\260\347\232\204\344\270\200\344\272\233\351\232\276\344\273\245\346\216\222\346\237\245\347\232\204\351\224\231\350\257\257.md" "b/_posts/2023-10-08-c-\345\274\200\345\217\221\346\227\266\351\201\207\345\210\260\347\232\204\344\270\200\344\272\233\351\232\276\344\273\245\346\216\222\346\237\245\347\232\204\351\224\231\350\257\257.md" index 6a87a50c10e4..9f23bd53f59b 100644 --- "a/_posts/2023-10-08-c-\345\274\200\345\217\221\346\227\266\351\201\207\345\210\260\347\232\204\344\270\200\344\272\233\351\232\276\344\273\245\346\216\222\346\237\245\347\232\204\351\224\231\350\257\257.md" +++ "b/_posts/2023-10-08-c-\345\274\200\345\217\221\346\227\266\351\201\207\345\210\260\347\232\204\344\270\200\344\272\233\351\232\276\344\273\245\346\216\222\346\237\245\347\232\204\351\224\231\350\257\257.md" @@ -52,7 +52,7 @@ size_t 通常用作存储容器尺寸的变量,但是该类型为无符号类 ## 模板超出最大递归限制 如果模板中定义了递归操作,需要额外注意模板递归的停止条件,例如下述代码: -```c++ +```C++ template int foo() { if (N == 1) return 1; @@ -62,7 +62,8 @@ int foo() { 上述代码想要利用模板求解1到N之和,但是编译器会给出模板实例化时超出限制的报错(`template instantiation depth exceeds maximum of 900`)。这是由于在实例化 `foo` 时,没有给定编译器的停止条件。 在 `C++17` 之前,上述问题可以通过特化模板来解决,如下述代码所示: -```C++template +```C++ +template int foo() { return N + foo(); }