From: mheaney@ni.net (Matthew Heaney)
Subject: Re: problems using classwide types
Date: 1997/06/25
Date: 1997-06-25T00:00:00+00:00 [thread overview]
Message-ID: <mheaney-ya023680002506972054030001@news.ni.net> (raw)
In-Reply-To: 33B10EF3.72B4@dcs.gla.NOSPAM.ac.uk
In article <33B10EF3.72B4@dcs.gla.NOSPAM.ac.uk>, andy billimore
<billimad@dcs.gla.NOSPAM.ac.uk> wrote:
>procedure Main is
> L_Check : Check_Type;
> TP : Transaction_Ptr_Type;
>begin
> TP := new Check_Type;
> TP := L_Check; -- Error (see below)
>end Main;
>So I can allocate enough memory to hold an object of Check_Type, but I
>can't assign anything to it which I don't understand.
You don't have a "classwide types" problem, you have an "access types" problem.
The object TP is an access object. It points to an object of type
Check_Type, but it not itself a Check_Type.
So when you do the assignment
TP := L_Check;
you are trying to assign an apple (Check_Type) to an orange (a pointer to
Check_Type).
Just do this
TP.all := L_Check;
and you should be fine.
Of course, you can combine steps:
TP : Transaction_Pointer_Type := new Check_Type'(L_Check);
which does heap allocation and initialization ("assignment") all in one
step. We wouldn't want to create any uninitialized objects, now would we,
hmmmm?
Hope that helps,
Matt
--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271
next prev parent reply other threads:[~1997-06-25 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-06-25 0:00 problems using classwide types andy billimore
1997-06-25 0:00 ` Matthew Heaney [this message]
1997-07-01 0:00 ` John English
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox