comp.lang.ada
 help / color / mirror / Atom feed
* orthogonal inheritance and extension aggregates
@ 2013-07-19 17:46 Felix Krause
  2013-07-19 18:00 ` Adam Beneschan
  2013-07-19 19:05 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 11+ messages in thread
From: Felix Krause @ 2013-07-19 17:46 UTC (permalink / 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/



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-07-22 22:03 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-19 17:46 orthogonal inheritance and extension aggregates Felix Krause
2013-07-19 18:00 ` 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

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