Visual Studio Compiler warning C4250 ('class1' : inherits 'class2::member' via dominance)

前端 未结 5 2094
梦毁少年i
梦毁少年i 2020-12-10 04:59

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
{
}

cla         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-10 05:40

    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() {};
    }; 
    

    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.

提交回复
热议问题