C++通过统治警告进行继承
我正在尝试实现一个相当大的对象,该对象实现了许多接口。其中一些接口是纯虚拟的。我可能在钻石继承方面遇到问题。 Visual Studio 报告 C4250 警告(“class1”:通过支配继承“class2::member”)
。首先,这些类实际上是按其应有的方式继承的。下面是导致这个问题的部分类设计。
A B C
\ / \ /
\ / \ /
AB BC
| |
| BC2
| |
\ D: Implementation of B, C, BC, BC2
\ /
Big
在整个树中,只有 D 实现了虚方法,没有其他相关方法的定义。 B 的所有虚方法都列在警告中。如果重要的话,D 是一个完整的类。
我读到这种情况发生在 Boost 序列化中,可以安全地忽略该警告。
我想要实现的这个方法有效吗?忽略此警告是否安全?
注1:这不是Visual Studio 编译器警告 C4250('class1':通过支配继承'class2::member'),我已经尝试了那里提出的解决方案。
注2:我也可以发送类图,但比这个复杂一点。
编辑: 完整警告如下:
warning C4250: 'gge::resource::ImageResource' : inherits
'gge::graphics::ImageTexture::gge::graphics::ImageTexture::drawin'
via dominance
绘图中的gge::resource::ImageResource
为Big,gge::graphics::ImageTexture
为D,drawin是六种方法之一我收到警告。
I'm trying to implement a rather large object that implements many interfaces. Some of these interfaces are pure virtual. I may have a problem in diamond inheritance. Visual Studio is reporting a warning of C4250 ('class1' : inherits 'class2::member' via dominance)
. First of all these classes are inherited virtually as it should be. The following is the partial class design that causes this problem.
A B C
\ / \ /
\ / \ /
AB BC
| |
| BC2
| |
\ D: Implementation of B, C, BC, BC2
\ /
Big
In this entire tree only D implements virtual methods, there is no other definition of the method in question. And all virtual methods of B is listed in warnings. If important, D is a complete class.
I read this happens with Boost serialization and it is safe to disregard the warning.
Is this method I am trying to achieve valid? Is it safe to disregard this warning?
Note 1: This is not a duplicate of Visual Studio Compiler warning C4250 ('class1' : inherits 'class2::member' via dominance), I have tried the solution proposed there.
Note 2: I can also send class diagram but its a little more complicated than this.
EDIT:
Full warning is as follows:
warning C4250: 'gge::resource::ImageResource' : inherits
'gge::graphics::ImageTexture::gge::graphics::ImageTexture::drawin'
via dominance
gge::resource::ImageResource
is Big in the drawing, gge::graphics::ImageTexture
is D, drawin is one of the six methods I get warning for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一切都是绝对有效的。编译器可以警告有效代码,这里没有问题。您可以尝试使用
using
声明来消除警告。如果这不起作用(可能是由于 MSVC bug),请使用pragma
将其静音。Everything is absolutely valid. A compiler is allowed to warn about valid code, no problem here. You can try silencing the warning with a
using
declaration. If this doesn't work (probably due to an MSVC bug), silence it with apragma
.