comp.lang.ada
 help / color / mirror / Atom feed
From: Felix Krause <flyx@isobeef.org>
Subject: orthogonal inheritance and extension aggregates
Date: Fri, 19 Jul 2013 19:46:38 +0200
Date: 2013-07-19T19:46:38+02:00	[thread overview]
Message-ID: <ksbu1u$75k$1@online.de> (raw)

I try to implement some feature via orthogonal inhertance like this:


    generic
       type Parent (<>) is abstract tagged private;
    package Extension is
       type Extended is abstract new Parent with private;

       -- operations of the extended type here
    private
       type Extended is abstract new Parent with record
          -- …
       end record;
    end Extension;


Now for testing, I tried to apply this on a Vector:


    package Int_Vectors is new Ada.Container.Vectors (Natural, Integer);
    package Base is new Extension (Int_Vectors.Vector);

    type Child is new Base.Extended with null record;


At the declaration of Child, GNAT tells me "type must be declared 
abstract or "To_Vector" overridden". Can someone explain why this 
happens? As I understand it, To_Vector should be automatically defined 
for the derived type. Is this because the intermediate type Extended is 
declared abstract? Or because To_Vector dispatches in the return type?

Anyway, I tried to declare the function for the type Child like this:


    function To_Vector (Length : Ada.Containers.Count_Type) return Child is
    begin
       return Child'(Base.Extended'(Int_Vectors.To_Vector (Length) with 
others => <>) with null record);
    end To_Vector;


Firstly, this looks rather awkward. Secondly, it doesn't compile: 
"expected private type Extended […] found a composite type". I guess 
this does not work because the type Extended is hidden in the private 
part of Extension. Is it possible to define To_Vector in this context 
to do exactly what the base function does?


-- 
Felix Krause
http://flyx.org/



             reply	other threads:[~2013-07-19 17:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-19 17:46 Felix Krause [this message]
2013-07-19 18:00 ` orthogonal inheritance and extension aggregates Adam Beneschan
2013-07-22 16:02   ` Adam Beneschan
2013-07-22 18:44     ` Dmitry A. Kazakov
2013-07-22 18:59     ` Adam Beneschan
2013-07-22 19:19       ` Adam Beneschan
2013-07-22 22:03       ` Felix Krause
2013-07-19 19:05 ` Dmitry A. Kazakov
2013-07-20  5:49   ` Randy Brukardt
2013-07-20  6:36     ` Dmitry A. Kazakov
2013-07-20  7:54       ` Niklas Holsti
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox