为什么“hello world”打印了三遍?我不清楚 C++ 结构中的虚拟继承。
#include<iostream>
using namespace std;
struct BS{
BS() {
cout << "hello world" << endl;
}
unsigned int color;
};
struct mid1 : virtual public BS { };
struct mid2 : virtual public BS { };
struct mid3 : public BS { };
struct mid4 : public BS { };
struct D : public mid1, public mid2, public mid3, public mid4 { };
int main() {
D d;
return 0;
}