Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • Well, an ugly solution for an ugly problem: Your examples are the prime motivation for the introduction of virtual inheritance in C++. Behind all these facades is always just a single person. In fact, this may be the best rationale for virtual inheritance I've read in a while (I didn't understand Stroustrup's reasoning, for example). So you could "compose by (multiple) inheritance" ;-). Commented Feb 16, 2022 at 16:39
  • Many TAs and some teachers are Phd students. And what about Student-teachers? We don't need to look vey far for real examples of this. Commented Feb 16, 2022 at 18:18
  • @Peter Virtual inheritance doesn't solve this. If you have two objects inheriting the same person, you have two instances of the same person, whether virtual or non-virtual inheritance. What you need is that Teacher, Student etc. hold a reference to the same Person object. Commented Feb 16, 2022 at 19:24
  • @gnasher Hm, true, I had in mind to have a class hierarchy student:virtual public person and a teacher:virtual public person and then create a teaching_student:teacher,student which would have only one person subobject. But composition is much better because it could change roles dynamically. Commented Feb 16, 2022 at 20:50
  • 1
    The truth, the whole truth and nothing but the truth, so help me Codd Commented Feb 17, 2022 at 9:09