TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Carlisle Martin C Dr USAFA/DFCS <[log in to unmask]>
Reply To:
Carlisle Martin C Dr USAFA/DFCS <[log in to unmask]>
Date:
Sun, 22 Sep 2002 19:50:31 -0600
Content-Type:
text/plain
Parts/Attachments:
text/plain (89 lines)
1) Put the derived class in a child package to gain visibility to the
private attributes.

2)       procedure Free_Active_Area is
         new Ada.Unchecked_Deallocation
            (Object => Active_Area_Type'Class,
             Name   => Active_Area_Access_Type);

I've written a couple of documents on OO that I'll attach to a private
email.

----------------------------------------------------------------------------
------
Martin C. Carlisle, PhD
Associate Professor and Advisor-in-Charge
Department of Computer Science
United States Air Force Academy


-----Original Message-----
From: Rick Duley [mailto:[log in to unmask]]
Sent: Sunday, September 22, 2002 7:46 PM
To: [log in to unmask]
Subject: Objects in Ada


Hi Teamers

I have been working on a class assignment in object-oriented programming and
have encountered a couple of curiosities.  The last time I did user-defined
OO I was using Borland Pascal Seven and Ada seems to provide a less
intuitive environment.  I think I am the last surviving Ada programmer in
the Perth education system and, with a dearth of texts which deal with Ada
OO, I am having real problems.

1. When I create a derived class, the methods of that class have no direct
assess to the attributes of the base class.  Therefore, to be able to
initialise an instance of the derived class I have to provide the
functionality in the base class to access those attributes, which has the
effect of making them public.  I am certain that students will ask why we go
to the trouble of making the tagged record private if we are then to go to
the trouble of making the data public.  Can someone provide me with an
explanation?

2.  Given the declaration:

      type Active_Area_Type is tagged limited private;

      type Active_Area_Access_Type is
      access all Active_Area_Type'Class;

if I then create an instance of the object by:

        Area : Active_Area_Access := new Active_Area_Type;


and at the end of the program run I want to deallocate the object using:

         procedure Free_Active_Area is
         new Ada.Unchecked_Deallocation
            (Object => Active_Area_Type,
             Name   => Active_Area_Access_Type);

I get an error message from the compiler (Gnat 3.13p) saying:

      'designated type of actual does not match that of formal "Name"'.

How can I deallocate objects?  I don't like having to leave the dirty work
up to the garbage collector.

Hoping someone will take the time to help here.
Thanks

---------------------------------------------------------

Rick Duley
School of Computing and Information Science
Edith Cowan University
2 Bradford St, Mt Lawley
Perth, Western Australia
tel: +61 8 9370 6619
fax: +61 8 9370 6100
mob: +61 040 910 6049                            /-_|\
                                                /     \
                                          perth *_.-._/
Experience is the worst of teachers                  v
          It gives you the exam
                        before it gives you the lecture

ATOM RSS1 RSS2