【发布时间】:2012-06-12 19:25:15
【问题描述】:
下面的代码显示了 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);
}
【问题讨论】:
-
我已编辑您的帖子以提供
main()。否则很好的问题,+1。
标签: c++ visual-studio-2010 templates default