gpt4 book ai didi

c++ - MSVC 2008 错误 'Type' 不是结构(尽管它是)

转载 作者:太空狗 更新时间:2023-10-29 19:52:22 26 4
gpt4 key购买 nike

以下 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com