<bdo id='zFbbn'></bdo><ul id='zFbbn'></ul>
  • <i id='zFbbn'><tr id='zFbbn'><dt id='zFbbn'><q id='zFbbn'><span id='zFbbn'><b id='zFbbn'><form id='zFbbn'><ins id='zFbbn'></ins><ul id='zFbbn'></ul><sub id='zFbbn'></sub></form><legend id='zFbbn'></legend><bdo id='zFbbn'><pre id='zFbbn'><center id='zFbbn'></center></pre></bdo></b><th id='zFbbn'></th></span></q></dt></tr></i><div id='zFbbn'><tfoot id='zFbbn'></tfoot><dl id='zFbbn'><fieldset id='zFbbn'></fieldset></dl></div>
      <legend id='zFbbn'><style id='zFbbn'><dir id='zFbbn'><q id='zFbbn'></q></dir></style></legend>

        <small id='zFbbn'></small><noframes id='zFbbn'>

        <tfoot id='zFbbn'></tfoot>

        Visual Studio 编译器警告 C4250(“class1":通过优势继承“class2::membe

        Visual Studio Compiler warning C4250 (#39;class1#39; : inherits #39;class2::member#39; via dominance)(Visual Studio 编译器警告 C4250(“class1:通过优势继承“class2::member))
              <bdo id='6tetB'></bdo><ul id='6tetB'></ul>

              <small id='6tetB'></small><noframes id='6tetB'>

                  <tbody id='6tetB'></tbody>
                1. <tfoot id='6tetB'></tfoot>

                2. <legend id='6tetB'><style id='6tetB'><dir id='6tetB'><q id='6tetB'></q></dir></style></legend>

                  <i id='6tetB'><tr id='6tetB'><dt id='6tetB'><q id='6tetB'><span id='6tetB'><b id='6tetB'><form id='6tetB'><ins id='6tetB'></ins><ul id='6tetB'></ul><sub id='6tetB'></sub></form><legend id='6tetB'></legend><bdo id='6tetB'><pre id='6tetB'><center id='6tetB'></center></pre></bdo></b><th id='6tetB'></th></span></q></dt></tr></i><div id='6tetB'><tfoot id='6tetB'></tfoot><dl id='6tetB'><fieldset id='6tetB'></fieldset></dl></div>
                  本文介绍了Visual Studio 编译器警告 C4250(“class1":通过优势继承“class2::member")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  以下代码生成警告 C4250.我的问题是,最好的解决方案是什么?

                  The following code generates warning C4250. My question is, what's the best solution to it?

                  class A
                  {
                    virtual void func1();
                  }
                  
                  class B : public A
                  {
                  }
                  
                  class C : public A
                  {
                    virtual void func1();
                  }
                  
                  class D : public B, public C
                  {
                  }
                  
                  int main()
                  {
                    D d;
                    d.func1(); // Causes warning
                  }
                  

                  根据我所读到的,应该可以这样做:

                  According to what I've read it should be possible to do this:

                  class D : public B, public C
                  {
                    using B::func1();
                  }
                  

                  但是,这实际上并没有做任何事情.我目前解决的方法是:

                  But, this doesn't actually do anything. The way I've currently solved it is:

                  class D : public B, public C
                  {
                    virtual void func1() { B::func1(); }
                  }
                  

                  大家对此有何看法?

                  推荐答案

                  我对以下代码有同样的警告:

                  I had the same warning for the following code:

                  class Interface
                  {
                  public:
                      virtual void A() = 0;
                  };
                  
                  class Implementation : public virtual Interface
                  {
                  public:
                      virtual void A() {};
                  };
                  
                  class ExtendedInterface : public virtual Interface
                  {
                      virtual void B() = 0;
                  };
                  
                  class ExtendedImplementation : public ExtendedInterface , public Implementation
                  {
                  public:
                      virtual void B() {};
                  }; 
                  

                  msdn 中 Visual C++ 2005 的错误报告建议这是一个已知的错误,被认为不足以修复......他们建议在这种情况下通过使用编译指示禁用警告.我认为这对您来说也是安全的,但您应该使用虚拟继承,如 Gal Goldman 的回答所示.

                  This bug report for Visual C++ 2005 in msdn suggests that this is a known bug that was considered not important enough to fix... They suggest to disable the warning in this case by using a pragma. I think it is safe also in your case, but you should use virtual inheritance as shown in the answer by Gal Goldman.

                  这篇关于Visual Studio 编译器警告 C4250(“class1":通过优势继承“class2::member")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  C++ stl unordered_map implementation, reference validity(C++ stl unordered_map 实现,参考有效性)
                  C++: Is it possible to use a reference as the value in a map?(C++:是否可以使用引用作为映射中的值?)
                  Where ampersand quot;amp;quot; can be put when passing argument by reference?(其中符号“amp;通过引用传递参数时可以放置吗?)
                  Why can a non-const reference parameter be bound to a temporary object?(为什么可以将非常量引用参数绑定到临时对象?)
                  What is a dangling reference?(什么是悬空引用?)
                  C++ reference changes when push_back new element to std::vector(当 push_back 新元素到 std::vector 时,C++ 引用发生变化)

                  <small id='eWW9H'></small><noframes id='eWW9H'>

                  <legend id='eWW9H'><style id='eWW9H'><dir id='eWW9H'><q id='eWW9H'></q></dir></style></legend>
                  <i id='eWW9H'><tr id='eWW9H'><dt id='eWW9H'><q id='eWW9H'><span id='eWW9H'><b id='eWW9H'><form id='eWW9H'><ins id='eWW9H'></ins><ul id='eWW9H'></ul><sub id='eWW9H'></sub></form><legend id='eWW9H'></legend><bdo id='eWW9H'><pre id='eWW9H'><center id='eWW9H'></center></pre></bdo></b><th id='eWW9H'></th></span></q></dt></tr></i><div id='eWW9H'><tfoot id='eWW9H'></tfoot><dl id='eWW9H'><fieldset id='eWW9H'></fieldset></dl></div>
                    <bdo id='eWW9H'></bdo><ul id='eWW9H'></ul>
                      <tbody id='eWW9H'></tbody>
                      <tfoot id='eWW9H'></tfoot>