Override virtual function of base classes, which do not share common interface

Viewed 5938
#include <iostream>
struct B1
{
    virtual void method()=0;
    virtual ~B1(){}
};

struct B2
{
    virtual void method()=0;
    virtual ~B2(){}
};

struct D: B1, B2
{
    virtual void method()
    {
        std::cout << "D::method\n";
    };
};

int main(int argc,char *argv[])
{
    D d;
    B1 &b1=d;
    B2 &b2=d;
    b1.method();
    b2.method();
    return 0;
}

Note, B1 and B2 do not share common interface.

Is it this legal? If yes - in which standard? C++98/03/11 ?

Both, msvc and gcc have compiled it OK.

Previously I thought, that I have to use some common interface for such case (possible virtual inheritence).

Does such situation have some special name?

How it works in details, please? Maybe some ISO references?

2 Answers
Related