Olu*_*ide 3 c++ templates friend visual-c++ language-lawyer
以下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()
{
}
Run Code Online (Sandbox Code Playgroud)
MSVC 2008错误
error C2649: 'Foo<T>::Type' : is not a 'struct'
Run Code Online (Sandbox Code Playgroud)
这是编译器错误还是我在这里做了非法的事情?更重要的是有修复吗?
删除struct关键字并将其替换为typename:
template<typename T>
struct Bar
{
friend typename Foo<T>::Type;
typedef typename Foo<T>::Type Foo;
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
83 次 |
| 最近记录: |