以下 MWE 在 gcc 4.8.2 上编译但不在 MSVC 2008 上编译(公司政策)
struct B
{
};
struct A
{
typedef B Handler;
};
template<typename T>
struct Foo
{
typedef typename T::Handler Type;
};
template<typename T>
struct Bar
{
friend struct Foo<T>::Type; // MSVC 2008 does not like this
typedef typename Foo<T>::Type Foo;
};
int main()
{
}
MSVC 2008 错误
error C2649: 'Foo<T>::Type' : is not a 'struct'
这是一个编译器错误还是我在这里做了一些非法的事情?更重要的是有修复吗?
最佳答案
删除struct
关键字并替换为typename
:
template<typename T>
struct Bar
{
friend typename Foo<T>::Type;
typedef typename Foo<T>::Type Foo;
};
关于c++ - MSVC 2008 错误 'Type' 不是结构(尽管它是),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26870724/