C++:钻石问题
简单的问题: 这种等级制度会导致DP吗?
//Abstract base class
class A {
//Implement pure virtual methods with a default definition.
//Pure virtual methods are still declared pure virtual.
};
//Abstract derived class
class B : public A {
//Define pure virtual methods with a default definition.
//Pure virtual methods are still declared pure virtual.
};
//Abstract base class
class C {
//Define pure virtual methods with a default definition.
//Pure virtual methods are still declared pure virtual.
};
//Concrete class
class D : public B, public C {
//Implement all methods from D, B, and C
};
Simple question:
Will this hierarchy cause a DP?
//Abstract base class
class A {
//Implement pure virtual methods with a default definition.
//Pure virtual methods are still declared pure virtual.
};
//Abstract derived class
class B : public A {
//Define pure virtual methods with a default definition.
//Pure virtual methods are still declared pure virtual.
};
//Abstract base class
class C {
//Define pure virtual methods with a default definition.
//Pure virtual methods are still declared pure virtual.
};
//Concrete class
class D : public B, public C {
//Implement all methods from D, B, and C
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,画图;所有基数都是唯一的:
“钻石问题”仅涉及由于多个重复基数而导致的不明确基类,例如,如果
D
是从A -> A 派生而来的。 B
和A -> C:
No. Draw the picture; all bases are unique:
The "diamond problem" only pertains to ambiguous base classes due to multiple repeated bases, e.g. if
D
were to derive from bothA -> B
andA -> C
: