comp.lang.ada
 help / color / mirror / Atom feed
* Inheritance with Ada types
@ 2010-02-09  2:16 Bryan
  2010-02-09  2:57 ` Hibou57 (Yannick Duchêne)
  2010-02-09 15:08 ` Robert A Duff
  0 siblings, 2 replies; 9+ messages in thread
From: Bryan @ 2010-02-09  2:16 UTC (permalink / raw)


I'm new to the OOP features of Ada and I'm trying to wrap my head
tagged types.  I've been reading the somewhat abstruse "Ada for
Software Engineers" and while I understand the examples in the text, I
would like to experiment on my own to further my understand.  I'm
trying to figure out how I can correctly--pardon my C++--"subclass" a
base class to create a new derived "class".  I created two simple
packges as follows:

parent.ads:

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package Parent is
  type Parent is abstract tagged private;
private
  type Parent is abstract tagged
    record
      Name: Unbounded_String;
    end record;
end Parent;

derived.ads:

with Parent; use Parent;
package Derived is
  type Derived is new Parent with private;
private
  type Derived is new Parent with
    record
      Sub_Name: Unbounded_String;
    end record;
end Derived;

I can compile parent.ads and the object file and ALI file are
produced.  I'm unable to get derived.ads to compile, however.  I get
the following error:

$ gnatmake -c parent derived.ads
gcc -c derived.ads
derived.ads:3:23: subtype mark required in this context
derived.ads:3:23: found "Parent" declared at parent.ads:2
derived.ads:5:23: subtype mark required in this context
derived.ads:5:23: found "Parent" declared at parent.ads:2
gnatmake: "derived.ads" compilation error

If I make the Derived type in a child package of the parent package, I
can get both interfaces to compile.  Perhaps I am misunderstanding
something about Ada OOP, but is it possible to have a derived package
that is not a child package of the base?  Must I use a child package,
or keep the derived type in the same package as the base type?



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

end of thread, other threads:[~2010-02-10  2:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-09  2:16 Inheritance with Ada types Bryan
2010-02-09  2:57 ` Hibou57 (Yannick Duchêne)
2010-02-09  9:11   ` Jean-Pierre Rosen
2010-02-09 10:19     ` Hibou57 (Yannick Duchêne)
2010-02-09 11:23       ` Jean-Pierre Rosen
2010-02-10  2:47         ` Randy Brukardt
2010-02-09 10:22     ` Hibou57 (Yannick Duchêne)
2010-02-09 15:08 ` Robert A Duff
2010-02-09 23:39   ` Bryan

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