From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: *** X-Spam-Status: No, score=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3d313337c39c5dd5 X-Google-Attributes: gid103376,public From: "Bob Fletcher" Subject: Re: run-time type identification Date: 1998/09/03 Message-ID: <01bdd73c$082f0230$f330ea9e@ukp03332>#1/1 X-Deja-AN: 387469682 References: <01bdd72e$49ee66b0$f330ea9e@ukp03332> Organization: Logica UK Limited Newsgroups: comp.lang.ada Date: 1998-09-03T00:00:00+00:00 List-Id: 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 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. >