From: Maciej Sobczak <no.spam@no.spam.com>
Subject: Re: Dynamically tagged expression required
Date: Fri, 09 Dec 2005 10:09:04 +0100
Date: 2005-12-09T10:09:04+01:00 [thread overview]
Message-ID: <dnbhjf$1fa$1@sunnews.cern.ch> (raw)
In-Reply-To: <2852224.m2vuDFxfOX@linux1.krischik.com>
Martin Krischik wrote:
>> A : Shape;
>> B : Shape'Class := A; -- (1)
>> C : Triangle := (SideLen => 7);
>>begin
>>
>> A := C; -- (2)
>> B := C; -- (3)
>>
>>end Hello;
>>Why is (1) allowed?
>
> because it is an initialization.
OK, so that explains why it's possible to use Shape'Class as a parameter
in subroutine. Every time the subroutine is called, the parameter is
*initialized* with the value, and therefore it can be different for each
call:
procedure Draw(S : Shape'Class);
T : Triangle;
R : Rectangle;
and later:
Draw(T); -- S initialized with T
Draw(R); -- S initialized with R
Right?
>>Why is (3) not allowed?
>
> because it is an assignment.
And this is where I want to dig deeper.
> http://en.wikibooks.org/wiki/Ada_Programming/Object_Orientation
This page says:
"The Class type is a real data type. You can declare variables of the
class-wide type, assign values to them [...]"
"Assign values to them" is a problem here.
As the subject of my original post says (and what compiler told me),
"dynamically tagged expression required".
What can I provide as a dynamically tagged expression?
It looks like some ShapeClassPtr.all is OK there, except that I get the
CONSTRAINT_ERROR, if the new value has a different tag. This observation
agrees with what Dmitry said - the tag of the class-wide object cannot
be changed.
What other dynamically tagged expression can be provided as a right-hand
side of the (default) assignment to the object of class-wide type?
Is this useful in practice?
Regards,
--
Maciej Sobczak : http://www.msobczak.com/
Programming : http://www.msobczak.com/prog/
next prev parent reply other threads:[~2005-12-09 9:09 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-08 13:50 Dynamically tagged expression required Maciej Sobczak
2005-12-08 14:46 ` Georg Bauhaus
2005-12-08 14:52 ` Dmitry A. Kazakov
2005-12-08 19:17 ` Martin Krischik
2005-12-09 9:09 ` Maciej Sobczak [this message]
2005-12-09 12:05 ` Jean-Pierre Rosen
2005-12-09 16:41 ` Robert A Duff
2005-12-09 20:18 ` Martin Krischik
2005-12-11 0:43 ` Matthew Heaney
2005-12-11 11:45 ` Martin Krischik
2005-12-11 14:24 ` Matthew Heaney
2005-12-11 15:18 ` Martin Krischik
2005-12-11 18:07 ` Matthew Heaney
2005-12-12 19:16 ` Martin Krischik
2005-12-13 20:43 ` Georg Bauhaus
2005-12-13 21:00 ` Georg Bauhaus
2005-12-09 20:41 ` Randy Brukardt
2005-12-09 20:16 ` Martin Krischik
2005-12-11 0:46 ` Matthew Heaney
2005-12-12 9:44 ` Maciej Sobczak
2005-12-12 19:13 ` Martin Krischik
2005-12-14 10:22 ` Maciej Sobczak
2005-12-15 20:10 ` Martin Krischik
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox