警告C4099:类型名首次使用'类'现在看到使用'struct'(MS VS 2k8) [英] Warning C4099: type name first seen using 'class' now seen using 'struct' (MS VS 2k8)

查看:1888
本文介绍了警告C4099:类型名首次使用'类'现在看到使用'struct'(MS VS 2k8)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是警告吗?我已经读过,它可以导致不稳定的行为?

Is this warning anything to worry about? I've read that it can cause erratic behaviour?

这是一个例子,我想编译,有人可以解释为什么作者声明的对象作为一个类但后来typedef它的结构?如果类是 POD ,这样做是否是正常的?

It's an example I'm trying to compile, could someone explain to me why the author declares the object as a class but then typedef's it to a structure? Is it perfectly normal to do so if the class is POD?

感谢。

推荐答案

与另一个(一个说类,另一个说结构)矛盾。给定一个定义规则,除了至多一个声明,所有声明必须是前向声明。警告通常指示类型的前向声明是错误的,并且通常是简单的拼写错误,并且应该是固定的。在这种情况下,应该没有副作用,但你真的应该修复它。

This warning appears when you have a one type declaration that contradicts another (one says "class", the other says "struct"). Given the one definition rule, all declarations except for at most one must be forward declarations. The warning will generally indicate that a forward declaration of a type is wrong and is usually a simple typo and should be fixed. In this case there should be no side effects, but you really should fix it.

但是,有一些非常讨厌的事情发生,如果你有类型名称冲突也许是由于使用使用命名空间子句或全局命名空间污染)。这些警告可能表示您正在混合来自两个不同库的标题,并且类型名称有冲突。在这些条件下编译的代码可以做一些非常意想不到的事情。

There can be, however, some very nasty things happen if you have type name clashes (perhaps caused by using "using namespace" clauses or global namespace pollution). These warnings could be indicating that you are mixing headers from two different libraries and the type names have clashes. Code compiled under these conditions could do some very unexpected things.

我的建议 - 理解为什么警告出现并修复它。如果警告是在第三方产品中,请坚持他们解决。

My advice - understand why the warning has appeared and fix it. If the warning is in a third party product, insist that they fix it.

这篇关于警告C4099:类型名首次使用'类'现在看到使用'struct'(MS VS 2k8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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