C++ Inheritance via dominance warning

巧了我就是萌 提交于 2019-11-27 11:19:42

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/6864550/c-inheritance-via-dominance-warning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!