C ++通过优势警告继承 [英] C++ Inheritance via dominance warning

查看:248
本文介绍了C ++通过优势警告继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实现一个相当大的对象实现许多接口。这些接口中的一些是纯虚拟的。我可能在钻石继承中有问题。 Visual Studio正在报告 C4250('class1':继承'class2 :: member'via dominance)的警告。首先,这些类实际上是继承的,因为它应该是。以下是导致此问题的部分类设计。

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

在整个树中,只有D实现了虚方法,没有其他方法的定义。并且B的所有虚拟方法都列在警告中。如果重要,D是一个完整的类。

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.

我读到这个发生Boost序列化,它是安全的忽略警告。

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?

注意1:这不是 我也可以发送类图,但它比这更复杂一点。我已经尝试过的解决方案提出了。

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.

EDIT:
完整警告如下:

Full warning is as follows:

warning C4250: 'gge::resource::ImageResource' : inherits 
'gge::graphics::ImageTexture::gge::graphics::ImageTexture::drawin' 
via dominance

gge :: resource :: ImageResource 在图中是大, gge :: graphics :: ImageTexture 是D,drawin是我警告的六种方法之一。

gge::resource::ImageResource is Big in the drawing, gge::graphics::ImageTexture is D, drawin is one of the six methods I get warning for.

推荐答案

一切都是绝对有效的。允许编译器对有效代码发出警告,这里没有问题。您可以尝试使用使用声明消除警告。如果这不工作(可能是由于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 a pragma.

这篇关于C ++通过优势警告继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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