Hal*_*alt 5 c++ templates default visual-studio-2010
下面的代码显示了2个Foo模板,每个模板有2个默认参数,Foo1有一个单独的原型而Foo2没有,否则它们是相同的.
为什么第一次调用Foo1会导致编译器(VS2010 Native C++)产生错误,而另外3个工作?
#include <limits>
// not needed but to prevent answers in this direction...
#undef max
#undef min
template< typename T >
void Foo1( T v1 = std::numeric_limits< T >::min(), T v2 = std::numeric_limits< T >::max() );
template< typename T >
inline
void Foo1( T v1, T v2 )
{
// ...
}
template< typename T >
inline
void Foo2( T v1 = std::numeric_limits< T >::min(), T v2 = std::numeric_limits< T >::max() )
{
// ...
}
int main()
{
Foo1<int>(0); /* Will cause error C2589: '::' : illegal token on right side of '::' */
Foo1<int>(0, 10);
Foo2<int>(0);
Foo2<int>(0, 10);
}
Run Code Online (Sandbox Code Playgroud)