From: Bryan <brobinson.eng@gmail.com>
Subject: Inheritance with Ada types
Date: Mon, 8 Feb 2010 18:16:14 -0800 (PST)
Date: 2010-02-08T18:16:14-08:00 [thread overview]
Message-ID: <ad9aca45-33dc-4765-a998-44a6b57dbe50@q16g2000yqq.googlegroups.com> (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?
next reply other threads:[~2010-02-09 2:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-09 2:16 Bryan [this message]
2010-02-09 2:57 ` Inheritance with Ada types 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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox