From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,YOU_INHERIT autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,5af5c381381ac5a7 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,UTF8 Path: g2news2.google.com!news3.google.com!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!feed118.news.tele.dk!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Newsgroups: comp.lang.ada Subject: Re: Ada requires too much typing! References: Date: Sun, 06 Jun 2010 14:04:33 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Martin Krischik" Organization: Martin Krischik, Softwareentwicklung Message-ID: User-Agent: Opera Mail/10.53 (MacIntel) NNTP-Posting-Host: 89.236.175.138 X-Trace: news.sunsite.dk DXC=n8kA9g_jTfd`;IS0i7S8TaYSB=nbEKnkk\1fh753F[M`IDiY_4:UK?cd3Nai^>E:QM5d2e^5VLiC>9fBYo8e21Pm9l X-Complaints-To: staff@sunsite.dk Xref: g2news2.google.com comp.lang.ada:12323 Date: 2010-06-06T14:04:33+02:00 List-Id: Am 06.06.2010, 12:13 Uhr, schrieb Simon Wright : > "Martin Krischik" writes: > >> One should just >> make a habit of defining classes like this: >> >> virtual Base >> { >> public: >> virtual ~Base () >> { >> … >> } >> } >> >> And suddenly all your virtual inheritance needs work flawlessly. > > I suppose there must be some cost to doing this? or the language > definition would require it to be always so. Yes indeed, you have virtual dispatch not only on the methods but on the instance variables as well. Sounds worth then it is. It means the internal structure of a child type changes from (Ada pseudo code): record Child_Type is Parent_Data : Parent_Type; end record to record Child_Type is Hidden_Parent_Data : Parent_Type; Parent_Data : constant access Parent_Type := Hidden_Parent_Data'Access; end record The compiler will ensure that Hidden_Parent_Data exist only once - but there may be any amount of Parent_Data which all point to the same Hidden_Parent_Data. And the funny part: The technology used to archive this is the very same you use to implement interfaces. Once you have the scaffolding for Interfaces in place you can have virtual base classes as well. Main problem with multiple inheritance was in C++ itself where default is “fast” not ”save”. For the Eiffel users it was never a problem because there virtual base classes are default. And I just see I made a mistake in my original post. It should have been: class Parent { public: virtual ~Parent () { … } } class Child virtual public Parent { … } but main problem stay: not enough C++ programmer have known about virtual inheritance and the diamond problem only pops up at Grand_Child level and lower (that means one has to plan ahead to avoid it). This in turn given multiple inheritance a bad name. But if you do it right it works just beautifully. The real lesson learned: “doing it right” must be default and “make it fast” must be an optional extra to be taught in very advanced level courses only. Martin -- Martin Krischik mailto://krischik@users.sourceforge.net https://sourceforge.net/users/krischik