HI, 我开始学习C++ STL的 我只是想他们中的一些小programs.one低于:C++模板查询
inline int const& max (int const& a, int const& b)
{
return a < b ? b : a;
}
template <typename T>
inline T const& max (T const& a, T const& b)
{
return a < b ? b : a;
}
int main()
{
::max(7, 42); // calls the nontemplate for two ints
::max<>(7, 42); // calls max<int> (by argument deduction)
::max('a', 42.7); // calls the nontemplate for two ints
}
我有一些基本的问题!
为什么在这里使用的作用域分辨率为 ?
为什么/如何 ,调用::最大<>(7,42)将 假定传递的参数是
的整数?
一条建议:像这样的const引用传递/返回int并不是真正的惯用法。只要做到这一点:“int max(int a,int b)” – Manuel 2010-02-08 13:05:40