comp.lang.ada
 help / color / mirror / Atom feed
From: Brian May <bam@snoopy.apana.org.au>
Subject: access types
Date: Sun, 01 Jul 2007 10:39:06 +1000
Date: 2007-07-01T10:39:06+10:00	[thread overview]
Message-ID: <sa4k5tlrm8l.fsf@margay.local> (raw)

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 <bam@snoopy.apana.org.au>



             reply	other threads:[~2007-07-01  0:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-01  0:39 Brian May [this message]
2007-07-01  1:54 ` access types Robert A Duff
2007-07-01  7:52   ` Dmitry A. Kazakov
2007-07-01 14:57     ` Robert A Duff
2007-07-01 19:41       ` Dmitry A. Kazakov
2007-07-02  0:12         ` Robert A Duff
2007-07-02  8:06           ` Dmitry A. Kazakov
2007-07-02 15:37       ` Adam Beneschan
  -- strict thread matches above, loose matches on Subject: below --
1999-07-15  0:00 Access Types Ronald Ayoub
1999-07-21  0:00 ` Robert A Duff
1999-07-22  0:00   ` Steve Folly
1999-07-23  0:00     ` Tucker Taft
1998-05-27  0:00 Access types jsanchor
1998-05-28  0:00 ` Jerry van Dijk
1998-05-29  0:00   ` jsanchor
1998-05-30  0:00     ` Jerry van Dijk
replies disabled

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