O
Old Wolf
Is the following code well-defined, and outputs foo twice?
#include <iostream>
struct Base1 { virtual void foo() = 0; };
struct Base2 { virtual void foo() = 0; };
struct Derived: Base1, Base2
{
void foo() { std::cout << "foo" << std::endl; }
};
int main()
{
Derived d;
Base1 *b1 = &d;
Base2 *b2 = &d;
b1->foo(); b2->foo();
}
#include <iostream>
struct Base1 { virtual void foo() = 0; };
struct Base2 { virtual void foo() = 0; };
struct Derived: Base1, Base2
{
void foo() { std::cout << "foo" << std::endl; }
};
int main()
{
Derived d;
Base1 *b1 = &d;
Base2 *b2 = &d;
b1->foo(); b2->foo();
}