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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,dfdb3e9be36e818e X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.15.105 with SMTP id w9mr21702804pbc.7.1321904760397; Mon, 21 Nov 2011 11:46:00 -0800 (PST) Path: lh20ni2604pbb.0!nntp.google.com!news1.google.com!postnews.google.com!o17g2000yqa.googlegroups.com!not-for-mail From: Yukicanis Newsgroups: comp.lang.ada Subject: Re: type access Parent'Class Date: Mon, 21 Nov 2011 11:44:05 -0800 (PST) Organization: http://groups.google.com Message-ID: <36568e75-43cb-4767-91de-cc8eb1db0abe@o17g2000yqa.googlegroups.com> References: <7fd768a4-f97b-4045-8bab-49d2a3897a61@p2g2000vbj.googlegroups.com> NNTP-Posting-Host: 93.208.169.211 Mime-Version: 1.0 X-Trace: posting.google.com 1321904760 14889 127.0.0.1 (21 Nov 2011 19:46:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 21 Nov 2011 19:46:00 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: o17g2000yqa.googlegroups.com; posting-host=93.208.169.211; posting-account=PkAoygoAAABk9hjFSCyiskOHSFxak1Yv User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HNKUARELSC X-HTTP-UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1,gzip(gfe) Xref: news1.google.com comp.lang.ada:19001 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2011-11-21T11:44:05-08:00 List-Id: On Nov 21, 8:33=A0pm, Robert A Duff wrote: > Yukicanis writes: > > Dear Group, > > > I'm new to Ada and currently playing around with its OOP features. > > Now, I have the following source: > > > procedure Test is > > =A0 type Parent is tagged limited null record; > > =A0 type Parent_Access is access Parent'Class; > > =A0 A : access Parent'Class; > > =A0 B : Parent_Access; > > =A0 procedure Dyn_Disp(X : access Parent'Class) is > > =A0 begin > > =A0 =A0 A :=3D X; > > =A0 =A0 B :=3D X; > > =A0 end Dyn_Disp; > > begin > > =A0 null; > > end Test; > > > When I try to complie that with GNAT 4.6.1 I get the following error > > message: > > > test.adb:9:10: expected type "Parent_Access" defined at line 3 > > test.adb:9:10: found type access to "Parent'Class" defined at line 6 > > > which I don't really understand since type "Parent_Access" is type > > access to Parent'Class, isn't it? > > No, there are three different access types -- Parent_Access, > the anonymous type of A, and the anonymous type of X. =A0They're all > "access to Parent'Class", but they are distinct. > > There are some implicit conversion rules that make "A :=3D X;" legal. > But there is no implicit conversion to Parent_Access, so "B :=3D X;" > is illegal. > > You normally want access-to-class-wide types (and many other access > types) to be "general", which is specified by adding "all": > > =A0 =A0 type Parent_Access is access all Parent'Class; > > If you do that, then you could say "B :=3D Parent_Access(X);" > or "B :=3D A.all'Access;". > > But I suggest you avoid anonymous access types, except in certain > special cases. =A0They are confusing. > > I also suggest you put most of your code in packages, rather than > in the main procedure. =A0That will also help avoid confusion, because > things behave differently when inside procedures. =A0For example, > you can't have any dispatching procedures unless you put the type > in a package spec. > > - Bob Thanks for your replay. I know that things behave differnetly in packages. I just wanted the minimal example to be as short es possible to avoid spamming.