【发布时间】:2014-03-07 01:44:01
【问题描述】:
对模板函数有点困惑。我有以下内容:
template <class T> T max (T v1, T v2)
double max(double v1, double v2) // non template
1)
int a = max(100, 200); // assuming max<int> is instantiated based on input param
2)
int a = max<int>(100.1, 200.1); // specialization triggers input type conversion
3)
double p = max<double>(100.1, 200.1); // specialization
4)
double p = max(100.1, 200.1); // non-template function used
(1) 没有 max 的调用是否有效?编译器如何处理这个? (3vs4) 编译器如何跟踪调用 max(double>() v/s max()?
【问题讨论】: