From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Free'ing dynamic abstract tagged types..
Date: Fri, 22 Sep 2006 09:21:29 +0200
Date: 2006-09-22T09:21:25+02:00 [thread overview]
Message-ID: <dh5jo88vgqrp.1c4nb3e0y08rf.dlg@40tude.net> (raw)
In-Reply-To: 1158872883.994303.80430@b28g2000cwb.googlegroups.com
On 21 Sep 2006 14:08:04 -0700, ldb wrote:
> Ok, so I have this abstract tagged type called Person (for the sake of
> discussion), and I have an Access_Person (which is access all
> people'class).
>
> I have some derived types, like Man and Child, with their own added
> fields. And I have defined Access_Man, Access_Child, as normal accesses
> to these types.
That usually were a bad idea, because it creates a parallel types
hierarchy:
Person <-- Man
Specific_Access_Person <-- Specific_Access_Man
Maintaining both is an unnecessary burden.
Note that you can allocate Man having Access_Person as the target. Usual
pattern is:
Man_Ptr : Access_Person := new Man;
-- OK, we want to access some fields of Man after having
-- created it, so:
declare
Object : Man'Class renames Man'Class (Man_Ptr.all);
begin
-- Do with Object what you have to with Man. Object
-- is not new, it is a Man'Class view of the thing pointed
-- by Man_Ptr.
...
end;
> I want to free an Access_Person that was dynamically allocated.
> ap : Access_Person;
> begin
> ap := Access_Person(new Man);
> free(ap);
> ...
Others have answered this.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2006-09-22 7:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-21 21:08 Free'ing dynamic abstract tagged types ldb
2006-09-21 22:12 ` Randy Brukardt
2006-09-22 7:41 ` Alex R. Mosteo
2006-09-26 0:08 ` Randy Brukardt
2006-09-21 22:12 ` Robert A Duff
2006-09-22 7:21 ` Dmitry A. Kazakov [this message]
2006-09-22 21:59 ` Jeffrey R. Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox