【发布时间】:2010-08-28 17:57:13
【问题描述】:
在下面的程序中,为什么编译器会为调用printMax模板函数而不是调用printMaxInts函数生成错误?
#include <iostream>
template<class A>
void printMax(A a,A b)
{
A c = a>b?a:b;
std::cout<<c;
}
void printMaxInts(int a ,int b)
{
int c = a>b?a:b;
std::cout<<c;
}
int main()
{
printMax(1,14.45);
printMaxInts(1,24);
}
【问题讨论】:
标签: c++ templates overload-resolution