-1

Just a quick silly question:

I was wondering if C++ makes use of the multiple inheritance feature provided by virtual inheritance internally. I know for sure that for the templated implementations such as the Data Structures provided by STL (std::vector <> for instance) cannot make use of such feature, but how about some other objects like streams for instance.

I know that multiple inheritance can be handy in some cases (for cross delegation, for example) but I feel like I should avoid it if C++ devs decided to avoided using such feature in their code.

Thanks everyone!

R34
  • 59
  • 6
  • 1
    The standard stream classes. – StoryTeller - Unslander Monica Jan 11 '18 at 17:57
  • 1
    See: http://en.cppreference.com/w/cpp/io – Richard Critten Jan 11 '18 at 17:57
  • Are you asking about multiple inheritance or virtual inheritance? – MikeMB Jan 11 '18 at 17:58
  • 2
    Don't use feelings to make programming decisions. Also [appeal to authority](https://www.logicallyfallacious.com/tools/lp/Bo/LogicalFallacies/21/Appeal-to-Authority) is a logical fallacy. – nwp Jan 11 '18 at 17:58
  • I can’t speak for the standard libraries, but it caused serious issues for frameworks that made heavy use of it, such as MFC. There’s a reason .NET doesn’t support it :) – zzxyz Jan 11 '18 at 18:00
  • 1
    @zzyz Actually, I've used several frameworks, such as the now defunct Reuters Triarch, that made very good use of MI - it's down tothe skill of the designers, really. –  Jan 11 '18 at 18:02
  • 1
    *implementations*, such as LLVM libc++ and GNU libstdc++, use multiple inheritance in about a dozen places, including inside an implementation detail of std::vector (what makes you think they "cannot" use it there?) Virtual inheritance - not so much, it's just the streams. – Cubbi Jan 11 '18 at 19:28

1 Answers1

8

iostream uses multiple and virtual inheritance; in particular, std::basic_iostream inherits from std::basic_istream and std::basic_ostream, and both of them inherit from std::basic_ios (with virtual inheritance).

That being said, iostream is not widely regarded as an example of great design, so take this information at face value (= yes, the standard includes classes that use multiple and virtual inheritance), and not as a stamp of good practice.

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299