comp.lang.ada
 help / color / mirror / Atom feed
From: "Bob Fletcher" <bob@radge.globalnet.co.uk>
Subject: Re: run-time type identification
Date: 1998/09/03
Date: 1998-09-03T00:00:00+00:00	[thread overview]
Message-ID: <01bdd73c$082f0230$f330ea9e@ukp03332> (raw)
In-Reply-To: m367f58j5g.fsf@zaphod.enst.fr

Yeah, this is the problem, there's no way of ensuring the safety of the
operation.

Also, in the code you give, are you certain that any record fields specific
to the class A2 would be copied by the assignment to the constant? It seems
likely to me that they would be lost. (I'll have a try when I get home from
work, as I don't have a compiler here). I imagine that invoking Z.All, in
your example, will return only the class A part of the object, regardless
of whether it is in fact an object of class A2.

As you rightly say, there will be problems if you try to do this in a
situation where you don't know whether the object in question is of the
base class or one of it's derived classes, which is what would really be
useful. The C++ dynamic_cast operator returns a zero (null) pointer if the
object being pointed to is not of the correct class.

Bob Fletcher
bob@radge.globalnet.co.uk
http://www.users.globalnet.co.uk/~radge/

Samuel Tardieu <sam@ada.eu.org> wrote in article 
> 
> You can do it in Ada: (pseudo-code that compiles but is obviously
incorrect)
> 
> package T is
>    type A is tagged null record;
>    type A2 is new A with null record;
>    type A_Ptr is access all A'Class;
>    Z : A_Ptr;
>    Y : constant A2 := A2 (Z.all);
> end T;
> 
> Of course, Constraint_Error will be raised if Z.all does not belong to 
> A2'Class.
> 





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

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-09-03  0:00 run-time type identification Bob Fletcher
1998-09-03  0:00 ` Tucker Taft
1998-09-03  0:00 ` Samuel Tardieu
1998-09-03  0:00   ` Bob Fletcher [this message]
1998-09-03  0:00     ` Matthew Heaney
1998-09-06  0:00       ` Samuel Tardieu
1998-09-03  0:00     ` Fergus Henderson
1998-09-03  0:00 ` Steve Sabljak
1998-09-03  0:00   ` Matthew Heaney
1998-09-03  0:00   ` Steve Sabljak
1998-09-03  0:00 ` Matthew Heaney
1998-09-03  0:00   ` Bob Fletcher
1998-09-03  0:00     ` Matthew Heaney
replies disabled

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