comp.lang.ada
 help / color / mirror / Atom feed
* premature use of private
@ 1999-08-17  0:00 tmoran
  1999-08-17  0:00 ` David C. Hoos, Sr.
  1999-08-17  0:00 ` Matthew Heaney
  0 siblings, 2 replies; 8+ messages in thread
From: tmoran @ 1999-08-17  0:00 UTC (permalink / raw)


I'm given an existing program that processes Apples with routines like
  function Is_Ripe(X : Apple) return Boolean;
  function Is_Red(X : Apple) return Boolean;
  function Size(X : Apple) return Integer;
and
  type Pile is array(integer range <>) of Apple;
  procedure Sort_By_Size(X : in out Pile);

I now need to add Oranges and Grapefruit and ...
So I tried

  type Fruit is abstract tagged private;
  function Is_Ripe(X : Fruit) return Boolean;
  function Size(X : Fruit) return Integer;

  type Apple is new Fruit with private;
  function Is_Red(X : Apple) return Boolean;

  type Orange is new Fruit with private;
  function Florida(X : Orange) return Boolean;

So far so good.  But I don't want a Pile of mixed Fruit, so,
borrowing from Barnes' on Containers, I tried:

  generic
    type This_Fruit is abstract tagged private;
    type Fruit_Ptr is access all This_Fruit;
  package Sets is
    type Pile is array(integer range <>) of Fruit_Ptr;
    procedure Sort_By_Size(X : in out Pile);
  end Sets;

  type Apple_Ptr is access all Apple;
  package Apples is new Sets(Apple, Apple_Ptr);

But that won't work because Apple is private at this point.

  How should this be done?




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

end of thread, other threads:[~1999-08-18  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-08-17  0:00 premature use of private tmoran
1999-08-17  0:00 ` David C. Hoos, Sr.
1999-08-17  0:00 ` Matthew Heaney
1999-08-17  0:00   ` tmoran
1999-08-17  0:00     ` David C. Hoos, Sr.
1999-08-18  0:00     ` Matthew Heaney
1999-08-18  0:00       ` tmoran
1999-08-18  0:00         ` Matthew Heaney

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