POV-Ray : Newsgroups : povray.off-topic : And today, C# : Re: And today, C# Server Time
11 Oct 2024 03:15:55 EDT (-0400)
  Re: And today, C#  
From: Warp
Date: 12 Feb 2008 12:03:20
Message: <47b1d157@news.povray.org>
Mike Raiford <mra### [at] hotmailcom> wrote:
> Ever attempted to use multiple inheritance in C++?

  Yes, I have needed it a few times. It's very handy.

  For example, recently I have been programming in a system where there
are basically two widget managers, each with their own widget types.
Both widget types have data inside them (such as their geometry) as
well as member functions. These widgets *need* those data members in
order to function properly.

  Usually these managers and their widgets can be kept separate, but in
this one case I needed to be able to gave the same objects to both
managers.

  Without multiple inheritance this would have been simply impossible.
I can't think of any way to accomplish this if multiple inheritance was
not supported. With C++'s multiple inheritance it worked beautifully.
I could create objects which were of both widget types at the same time,
and which could be given to both widget managers without even the
slightest of problems.

  I just can't even begin to imagine how I could have done this eg. in
Java. (At least not without crippling the system really badly and making
it really cumbersome to use.)

> Things get really 
> interesting when you have more than one base class, and some members 
> overlap.

  Ambiguity problems may sometimes happen, but rarely, and when they do,
it's seldom a problem.
  If, for example, both base classes have a function with the same name
and you need to call it for a derived class, you simply specify which
one should be called. It's basically no different than if the functions
in the base classes were named differently.

  Besides, it's not like two Java/C# interfaces couldn't have functions
with same names... (Ok, I have to admit that I don't know if they can,
but I assume they do.) This is not a problem exclusive to C++.

> There are other issues, of course, such as which copy of the 
> base class is used when 2 classes share a common base class and are 
> inherited by a further derived class. (Looks like a diamond on an 
> inheritance diagram)

  Just avoid diamond inheritance if you are unsure. It's not that hard.

  Being able to inherit from two (completely distinct) classes is extremely
handy regardless.

> Use C# for a while, especially the newer version (3.0) It's actually 
> quite nice. I've sort of grown to like it since I've started actually 
> using it. C++ish syntax, some stuff borrowed from Java.

  I don't like languages which artificially limit what I can do just
because the creators feared diamond inheritance.

  (I have never understood, and never will understand why they disallow
multiple inheritance *completely* given that the only problem they fear
is *diamond inheritance*. Why not disallow diamond inheritance? That
would solve the problem.)

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.