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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,b0ad1d51e4ffa82b,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!sn-xt-sjc-04!sn-xt-sjc-01!sn-post-sjc-02!sn-post-sjc-01!supernews.com!corp.supernews.com!not-for-mail From: Brian May Newsgroups: comp.lang.ada Subject: access types Date: Sun, 01 Jul 2007 10:39:06 +1000 Organization: Posted via Supernews, http://www.supernews.com Message-ID: User-Agent: Gnus/5.110006 (No Gnus v0.6) XEmacs/21.4.19 (linux) Cancel-Lock: sha1:GGmtQkqmF3YIy/ynT6CfsA96eto= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@supernews.com X-Original-Bytes: 2156 Xref: g2news1.google.com comp.lang.ada:16364 Date: 2007-07-01T10:39:06+10:00 List-Id: Hello, Ok, so maybe my Ada is rusty. However, I had a situation where I want to do the following: === cut === package a is type X is tagged private; ... type X_reference is access X'class; ... type Y is new X with private; procedure do_stuff(my_object : in out Y); ... type Y_reference is access Y'Class; ... end a package b is procedure save_reference(my_object : in X_reference); end b; and I want to be able to do: declare U : Y_reference; V : X_reference; begin U := new Y; do_stuff(U.all); V := U; save_reference(V); end; === cut === notes: - do_stuff is not defined for X only Y, so I can't skip the Y_reference and go straight to a X_reference. - not compiled; but hopefully understandable The problem is the 2nd last instruction (V := U) won't compile, as the compiler complains it is not possible to convert a Y_Reference to a X_Reference; Is it possible to convert a Y_reference to a X_reference? As the X_reference can access X'Class, which presumable includes Y'Class, I thought it should be possible somehow, without creating a separate copy of the object. (yes, maybe it would be ideal if I didn't need so many access types, however these objects need to be referenced from multiple objects and access types would seem the most natural solution). Thanks. -- Brian May