Two default parameters in the template, what is wrong here?

The code below shows 2 Foo templates with two default parameters, Foo1 has a separate prototype, and Foo2 does not, they are the same otherwise.

Why would the first call in Foo1 cause the compiler (VS2010 Native C ++) to produce an error while the other 3 work?

#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);
}
+5
source share
1 answer

This is a compiler error, as reported here . The workaround is as follows:

. , , . , . , PCH .

, Visual ++

+3

All Articles