comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@world.std.com>
Subject: Re: package dependence question
Date: 2000/05/30
Date: 2000-05-30T00:00:00+00:00	[thread overview]
Message-ID: <wccog5o809g.fsf@world.std.com> (raw)
In-Reply-To: 8gt19i$1cm8@r02n01.cac.psu.edu

Carl Banks <oaf@psu.edu> writes:

> My question is, is there a better way to define such a doubly-
> traversible tree, so that different node types need not be defined in
> the same package?

There is no ideal solution to this problem in Ada 95 (although the ARG
is currently working on a language modification that will solve the
problem nicely).

One thing you can do is declare tagged type Node, and then "type
Node_Ptr is access all Node'Class;".  Make types A, B, and C derive from
Node.  Then B can have a component like "Parent: Node_Ptr;".  You lose
type checking -- the parent of a B is always an A, but the code doesn't
say so, except in a comment.

Another way to have mutually-recursive types is to create a dummy parent
type for one or more of the types.  Eg, if you have X and Y that point
to each other, you can declare Dummy_X and Dummy_Y as null records, and
point to Dummy_X'Class and Dummy_Y'Class.  Then X is derived from
Dummy_X, adding the actual record components.  Similarly for Y.

- Bob




  parent reply	other threads:[~2000-05-30  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-05-29  0:00 package dependence question Carl Banks
2000-05-29  0:00 ` Robert Dewar
2000-05-29  0:00 ` Antonio Dur�n Dom�nguez
2000-06-03  0:00   ` Robert I. Eachus
2000-05-29  0:00 ` Jeff Carter
2000-05-29  0:00   ` Ray Blaak
2000-05-30  0:00 ` Robert A Duff [this message]
2000-05-30  0:00   ` Ray Blaak
2000-05-30  0:00   ` Brian Rogoff
replies disabled

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