comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: How to write TYPECASE in Ada 95?
Date: 1999/02/06
Date: 1999-02-06T00:00:00+00:00	[thread overview]
Message-ID: <m3679fz3wv.fsf@mheaney.ni.net> (raw)
In-Reply-To: 0JJEkbcU#GA.219@pet.hiwaay.net

"David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> writes:

> procedure Test_Points is
> 
>    -- Since an object of Points.Point'Class must be constrained at the time
> of
>    -- declaration to some one of the types derived from Points.Point, and
>    -- therefore cannot be re-used for other types derived from Points.Point,
>    -- we use an access object, instead.  But first, we declare the type of
>    -- that access object, as well as a deallocation procedure for it.
>    type Point_Class_Access is access all Points.Point'Class;
> 
>    procedure Free is new Ada.Unchecked_Deallocation
>      (Object => Points.Point'Class,
>       Name   => Point_Class_Access);
> 
>    -- We do not need to initialize this access object here, but we do so
>    -- just to illustrate that it can be done.
>    P_Access : Point_Class_Access := new Points.Tall_Point'(3.0, 4.0, 5.0);


Note that there's another way to illustrate these concepts, that does
not require heap.  Just use a declare block to declare each new kind of
point, as follows:

with Ada.Text_Io;
with Ada.Unchecked_Deallocation;
with Points; use Points;
procedure Test_Points is
begin

   declare
      P : Tall_Point := (3.0, 4.0, 5.0);
   begin
      Points.Show_Type (P);
      Points.Show_Properties (Point'Class (P));
   end;

   declare
      P : Painted_Point := (3.0, 4.0, Points.Blue);
   begin
      Points.Show_Type (P);
      Points.Show_Properties (Point'Class (P));
   end;

end Test_Points;



Declare blocks are your friend.  Unnecessary use of heap is your enemy.





  reply	other threads:[~1999-02-06  0:00 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-02-05  0:00 How to write TYPECASE in Ada 95? Norman Ramsey
1999-02-05  0:00 ` Brian Rogoff
1999-02-05  0:00   ` David C. Hoos, Sr.
1999-02-05  0:00     ` Brian Rogoff
1999-02-06  0:00   ` Ed Falis
1999-02-06  0:00     ` Nick Roberts
1999-02-06  0:00       ` Nick Roberts
1999-02-17  0:00     ` Tom Moran
1999-02-18  0:00       ` Matthew Heaney
1999-02-18  0:00         ` robert_dewar
1999-02-19  0:00           ` Nick Roberts
1999-02-19  0:00           ` Tom Moran
1999-02-18  0:00         ` Tom Moran
1999-02-18  0:00         ` Tom Moran
1999-02-18  0:00           ` Matthew Heaney
1999-02-19  0:00     ` Tom Moran
1999-02-19  0:00       ` Tom Moran
1999-02-23  0:00       ` Samuel Mize
1999-02-23  0:00         ` Question (was Re: How to write TYPECASE in Ada 95?) Mike Silva
1999-02-24  0:00           ` Samuel T. Harris
1999-02-24  0:00             ` Matthew Heaney
1999-02-24  0:00               ` Tucker Taft
1999-02-24  0:00           ` Nick Roberts
1999-02-24  0:00           ` (long) programming by extension (was: " Samuel Mize
1999-02-24  0:00             ` (long) programming by extension Samuel Mize
1999-02-25  0:00               ` (shorter and new) " Samuel Mize
1999-02-25  0:00                 ` Mike Silva
1999-02-26  0:00                   ` Samuel Mize
1999-02-06  0:00 ` How to write TYPECASE in Ada 95? David C. Hoos, Sr.
1999-02-06  0:00   ` Matthew Heaney [this message]
1999-02-06  0:00     ` Matthew Heaney
1999-02-06  0:00     ` Matthew Heaney
1999-02-09  0:00     ` David C. Hoos, Sr.
1999-02-06  0:00 ` Matthew Heaney
replies disabled

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