comp.lang.ada
 help / color / mirror / Atom feed
From: Rusnak <bogus@nowhere.com>
Subject: Re: Destructor question
Date: 1998/12/03
Date: 1998-12-03T00:00:00+00:00	[thread overview]
Message-ID: <3666F7F1.9B107D38@nowhere.com> (raw)
In-Reply-To: 3666BACC.99E6BB06@spam.innocon.com

Jeff Carter wrote:

> Rusnak wrote:
> >
> > How are destrcutor methords properly implemented in Ada on tagged
> > records?  I have the following setup:
> > ...
>
> Assuming
>
> "destrcutor" should be "destructor"
>
> and
>
> "methords"   should be "methods"
>
> then the answer to this question is that Ada does not have methods, much
> less destructor methods. Ada has subprograms and entries.
>
> This is a MicroStuff Support answer: technically correct but useless.
> Here's a useful answer:
>
> Your question seems to be about what Ada calls "finalization", which
> refers to operations on objects of a type when the value of the object
> becomes inaccessible (prior to assignment or when the object ceases to
> exist). I refer you to the standard package Ada.Finalization for the
> details of finalization in Ada (ARM 7.6).
>
> --
> Jeff Carter
> E-mail: carter commercial-at innocon [period | full stop] com
> "Perfidious English mouse-dropping hoarders."
> Monty Python & the Holy Grail

  Sorry about the spelling mistakes on earlier post.  The key terms
"method" and "attribute" are object-oriented terms (which I believe are now
accepted as part of UML but I can be wrong about that) and are not
associated with any particular language.  I would agree that Ada class
objects do not have a "this" pointer, but tagged records do support
dispatching operations which are essentially "methods" of the class.

Now to the more important question:  I assume that IF I am going to use the
Ada.Finalization package, that all my tagged records should be based off of
the Controlled type within that package.  I would may also have to override
the Finalize procedure since a derived class could allocate memorey for new
attributes of the tagged record.  The Finalize, Initialize, and Ajust
procedures do NOT take an access type however.  What I  have is an array of
access values to a "'Class" type, and I need to deallocate the memory
associated with each of the access values.  One cannot write an
Unchecked_Deallocation for a "'Class" object (this makes sense).  What I
need is to write is a dispaching procedure (i.e. a mehotd of a class) like
the following:

    Given a type Instance which is an abstract tagged record and a type
Object which is of type access all Instance and a type Class_Object which
is of type access all Instance'Class,
I would like to define a procedure:

    procedure Deallocate(The_Object : in out Object) is abstract;

which is dispatching.  The compiler certainly lets me declare such a
procedure, but I can never use it, since it cannot accept a  parameter of
type Class_Object to get it to dispatch.  Another solution is possible, but
the above solution (if "implementable") would be the cleanest  and least
intriusive way to go.

On another note,  if i override a proceudre in a derived class, how can I
"chain" it to its super class (i.e.,  call  within the procedure the super
class procedure which it overrides)?  I could certainly see the use in
chaining  the Initialize procedure of the Controlled class mentioned
above.  Explicit casting doesn't seem to work, and casting is not a very
desirable solution anyway.

-John






  reply	other threads:[~1998-12-03  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-12-02  0:00 Destructor question Rusnak
1998-12-03  0:00 ` Jeff Carter
1998-12-03  0:00   ` Rusnak [this message]
1998-12-04  0:00     ` Robert I. Eachus
1998-12-06  0:00       ` Matthew Heaney
1998-12-08  0:00         ` Robert I. Eachus
1998-12-06  0:00     ` Matthew Heaney
1998-12-07  0:00     ` Jeff Carter
1998-12-06  0:00 ` Matthew Heaney
1998-12-06  0:00 ` david.c.hoos.sr
1998-12-06  0:00   ` Matthew Heaney
1998-12-08  0:00   ` Robert I. Eachus
replies disabled

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