我对以下代码有疑问:
template <typename T>
void foo(struct bar & b);
struct bar {};
int main(){}
它在 GCC 上编译成功,但在 MSVC (2008) 上编译失败并出现以下错误:
C2990:“bar”:已声明为类类型的非类类型
是代码错误还是 MSVC 中的错误?
如果我在模板定义之前添加 struct bar; 就可以了。
最佳答案
我们有我们的赢家:
Thank you for reporting this issue. This is indeed a case of non-conformant behaviour in VC++. However, a simple workaround is to reorder the declarations so that the declaration "struct bar" is known when the template declaration is encountered. Due to the low severity of this bug and our priorities, we regret that we cannot fix the bug in the next release of the compiler but we will consider it for a future release.
Regards,
Tanveer Gani Visual C++ Team
关于c++ - 前向声明的类型和 "non-class type as already been declared as a class type",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5995774/