POV-Ray : Newsgroups : povray.off-topic : And today, C# : Re: And today, C# Server Time
11 Oct 2024 03:16:05 EDT (-0400)
  Re: And today, C#  
From: Warp
Date: 20 Feb 2008 19:26:32
Message: <47bcc537@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> Warp wrote:
> >   That still doesn't solve the problem of virtual inheritance being
> > either always-on or always-off for a class in a precompiled library,
> > without any possibility of changing it on a per-program basis.

> I'm not sure what "virtual inheritance" means outside the very narrow 
> context of C++. And inside that context, I'm not sure I understand what 
> problem it's supposed to be solving.

  Virtual inheritance is related to diamond inheritance.

  Any OOP language which supports multiple inheritance, and consequently
diamond inheritance, must resolve the problem in one way or another.
Virtual inheritance in C++ is one solution.

  When you use virtual inheritance in diamond inheritance situations,
the base class appears in the object only once, and all the derived
objects use that one single instance of the base class object (instead
of each using their own).

  Naturally this requires that all the access to the base class members
be indirect. They cannot be accessed directly but only through a vtable.
Since having to access all member variables indirectly would be a
completely useless overhead in non-diamond-inheritance situations, this
is not done by default.

  The problem is that classes derived from a common base class need to
make the decision of whether they will use virtual inheritance or not.
Using virtual inheritance will allow diamond inheritance with a common
base class. However, if this is not needed, then virtual inheritance
would be completely useless overhead.

  When these derived classes are in a precompiled library which cannot
be changed, the decision cannot be changed either. They either use
virtual inheritance (allowing diamond inheritance with a single base
class) or they don't. If they don't, and you would need it, bad luck.

  That's the reason why precompiled libraries sometimes may introduce
problematic situations.

  Fortunately it's rare to need to use diamond inheritance in the first
place (and in many cases where diamond inheritance is needed, the common
base class isn't). Thus the problem appears quite rarely.

-- 
                                                          - Warp


Post a reply to this message

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