成员函数模板参数默认值

Olu*_*ide 1 c++ templates function-templates default-arguments

以下位代码在GCC 4.5.3中编译,但不在VS 2008和2010中编译.这是由于VS编译器错误还是标准禁止给出默认函数模板参数值?

#include <cstdlib>

struct Bar
{
    enum Group{ A , B , C };
};

struct Foo
{
    template<typename T>
    static void getSome( typename T::Group = T::A );
};

template<typename T>
void Foo::getSome( typename T::Group )
{
};

int main()
{
    Foo::getSome<Bar>();            // Does not compile in VS 2008 & 2010 (compiles in gcc 4.5.3)
    Foo::getSome<Bar>( Bar::C );    // Compiles in VS 2008 and gcc 4.5.3
    return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

错误信息

prog.cpp(11) : error C2589: '::' : illegal token on right side of '::'
prog.cpp(11) : error C2059: syntax error : '::'
Run Code Online (Sandbox Code Playgroud)

Dre*_*ann 6

这是一个MSVC错误.

正如您可能猜到的那样,错误在于使用默认参数处理模板函数.

他们的解决方法是提供所有功能参数. (呸)

在此承认.