0

Currently i try to understand the caveats from virtual inheritance better because i am thinking to usethem (delegate to sister class). I use the following example from https://isocpp.org/wiki/faq/multiple-inheritance

#include <iostream>

class Base { 
public:  
    virtual void foo() = 0;  
    virtual void bar() = 0; 
}; 

class Der1 : public virtual Base { 
public:  
    virtual void foo();
}; 

void Der1::foo() { 
    bar(); 
}

class Der2 : public virtual Base { 
public:  
    virtual void bar(); 
}; 

void Der2::bar() {
    std::cout << "Der2::bar()" << std::endl;
}

class Join : public Der1, public Der2 {
public:  
    // ...
};

int main() {  
    Join* p1 = new Join();  
    Der1* p2 = p1;  
    Base* p3 = p1;  
    p1->foo();  
    p2->foo();  
    p3->foo();
}

With TDM-GCC-32 (gcc 4.9.2) i compile it with

    g++ test.cpp -Wall -Wpedantic -o test.exe

and i get absolute no errors or warnings.

With MSVC-2013 (VS-12 Update 4) i get the following warnings

    warning C4250: 'Join': Erbt 'Der1::Der1::foo' via Dominanz

Why does Visual Studio warn me and gcc not? Do i need to worry about warning C4250?

schorsch_76
  • 794
  • 5
  • 19

1 Answers1

0

You can read what C4250 means here:

What does C4250 VC++ warning mean?

Possible way of solving through virtual inheritance here:

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

Community
  • 1
  • 1
demonplus
  • 5,613
  • 12
  • 49
  • 68