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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,63fa88e2f1a3ebea X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!fr.ip.ndsoftware.net!62.141.58.147.MISMATCH!newsfeed.keyweb.org!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Universal type in Ada Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Thu, 16 Jun 2005 13:59:43 +0200 Message-ID: NNTP-Posting-Date: 16 Jun 2005 13:59:43 MEST NNTP-Posting-Host: ef8bfc1c.newsread2.arcor-online.net X-Trace: DXC=D;h>ml;SYTo;XK28C2J>>hQ5U85hF6f;djW\KbG]kaMhFYk:AnJB[Cm\ZOZg1d_T4o[6LHn;2LCVn7enW;^6ZC`d<=9bOTW=MNn X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:11411 Date: 2005-06-16T13:59:43+02:00 List-Id: On 16 Jun 2005 10:18:44 +0200, Ole-Hjalmar Kristensen wrote: > Please do not do this. As someone (may have been John Max Skaller) on > comp.lang.c++ said once, "casting is something you do when fishing". > Think about what you are trying to do, and try to figure out how this > can be accomplished by the tools available to you in Ada, like > generics or run-time polymorphism. Yes, but unfortunately, there is one case in Ada 95 where apparently unnecessary downcasting is necessary: pool-specific access types to class-wide objects: type Object is tagged ...; type Object_Ptr is access Object'Class; function Create_My_Object (...) return Object_Ptr is Result : Object_Ptr; begin Result := new My_Object (...); declare This : My_Object renames M_Object (Result.all); -- Casting is required because a pool-specific access -- to My_Object is not convertible to a pool-specific -- access to Object'Class! begin -- Do whatever needed to complete initialization of -- This ... end; return Result; end Create_My_Object; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de