Skip to content

败犬日报 2025-07-29

1. 又一个重载决议的例子

cpp
#include <cstdio>

template <typename T>
void foo(T t) {
    printf("T\n");
}

template <typename T>
void foo(T* t) {
    printf("T*\n");
}

int main() {
    foo(114);
    int a = 514;
    foo(&a);
}

输出是 TT*,很符合直觉。

但是直觉的背后是一套超级复杂的规则决定哪个特化是最匹配的。