【发布时间】:2018-09-03 11:29:23
【问题描述】:
以下代码是否符合 C++ 标准?
struct B
{
protected:
struct Type {};
};
struct D : B, B::Type
{};
int main()
{
D d;
return 0;
}
我在Compiler Explorer 上试过。 MSVC(VS 2017 RTW)接受它。 gcc(7.3) 和 clang(6.0.0) 拒绝它。
【问题讨论】:
-
不知道,但您已经证明,无论标准怎么说,您都不能依赖行为,所以不要。一种解决方法是只使用两个级别的类派生(继承)。
标签: c++ inheritance multiple-inheritance protected