模板化类的模板化成员的编译失败.VC++有效,但G ++失败了

Eoi*_*oin 2 c++

以下代码在Visual C++ 2010下编译良好,但在Android NDK r8b下不在GCC 4.6下编译.

template<typename A>
struct foo
{
    template<typename B>
    B method()
    {
        return B();
    }
};

template<typename A>
struct bar
{
    bar()
    {
        f_.method<int>(); // error here
    }

private:
    foo<A> f_;
};
Run Code Online (Sandbox Code Playgroud)

GCC给出的错误是

error : expected primary-expression before 'int'
error : expected ';' before 'int'
Run Code Online (Sandbox Code Playgroud)

对于标记线.对于我的生活,我无法弄清楚什么是错的.

Seg*_*ult 8

GCC是正确的,因为f_类型foo<A>取决于模板参数A,您需要method使用template关键字限定调用:

f_.template method<int>();  // This will work
Run Code Online (Sandbox Code Playgroud)