前向声明类型和“非类类型已声明为类类型" [英] Forward-declared type and "non-class type as already been declared as a class type"

查看:46
本文介绍了前向声明类型和“非类类型已声明为类类型"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码的问题:

  template <typename T>
  void foo(struct bar & b);
  struct bar {};
  int main(){}

它在 GCC 上编译成功,但在 MSVC (2008) 上失败并出现以下错误:

It compiles successfuly on GCC, but fails on MSVC (2008) with following error:

C2990: 'bar' : 非类类型已被声明为类类型

是代码错误还是 MSVC 中的错误?

Is the code wrong or it's a bug in MSVC?

如果我在模板定义之前添加 struct bar; 就可以了.

It works if I add struct bar; before template definition.

推荐答案

我们有了我们的赢家:

https://connect.microsoft.com/VisualStudio/feedback/details/668430/forward-declared-type-and-non-class-type-as-already-been-声明为类类型

感谢您报告此问题.这确实是一个案例VC++ 中的不一致行为.但是,一个简单的解决方法是重新排序声明,以便声明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.

问候,

坦维尔加尼Visual C++ 团队

Tanveer Gani Visual C++ Team

这篇关于前向声明类型和“非类类型已声明为类类型"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆