被嗆我難過,回家反省,確定這個直接 template-meta 的版本沒人給過
#include <cstdio>
template <int N, int M> struct p {
static void foo() {
printf("%2d x %2d = %2d\n", N, M, N * M); p<N, M + 1>::foo();
}
};
template <int N> struct p<N, 9> {
static void foo() {
printf("%2d x %2d = %2d\n", N, 9, N * 9); p<N + 1, 1>::foo();
}
};
template <> struct p<9, 9> {
static void foo() {
printf("%2d x %2d = %2d\n", 9, 9, 9 * 9);
}
};
int main() {
p<1, 1>::foo();
}
等等來試試看 main recursive