当我有两个这样的模板化函数重载时:
template<class T>
void foo( T const& )
{
// do something with a const reference
cout << "const reference version";
}
template<class T>
void foo( T const* )
{
// do something with a const pointer
cout << "const pointer version";
}
为什么编译器在使用非常量指针类型实例化时会选择第一个版本?
int* bar;
foo( bar ); // prints "const reference version"
char const* baz;
foo( baz ); // prints "const pointer version"