假设我有一个函数的两个重载版本
为什么
template <typename T>
void f(const T&) {
cout << "f(T&)" << endl;
}
template <typename T>
void f(const T*) {
cout << "f(T*)" << endl;
}
为什么
f(new int)
解析为f(const T&)
而不是f(const T*)
?标准文档中是否有关于这种反直觉行为的讨论?
http://ideone.com/kl8NxL
f(new int)
解析为f(const T&)
,其中T
设置为int*
,而不是int
。就像您调用签名为f(int* const&)
的函数一样。 - R Sahuf(int* const&)
比f(const int*)
更匹配? - Kan Li