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,93785bd6b32ae669 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!v39g2000pro.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Programming by interface in Ada Date: Wed, 13 Aug 2008 08:31:54 -0700 (PDT) Organization: http://groups.google.com Message-ID: <7e79c4ad-d196-4372-8974-6de9b9baaea1@v39g2000pro.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1218641515 546 127.0.0.1 (13 Aug 2008 15:31:55 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 13 Aug 2008 15:31:55 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: v39g2000pro.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:1610 Date: 2008-08-13T08:31:54-07:00 List-Id: On Aug 13, 4:14 am, S=E9bastien Morand wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi, > > I'm trying to do the following thing: > > - --- pkginterface.ads ------------------------------- > with ObjInterface; use ObjInterface; > > package PkgInterface is > > -- Mon interface class > type MonInterface is interface; > type MonInterfacePtr is access all MonInterface; > > procedure SetObjet(r: in out MonInterface; c: in MonCount; o: in > MonObjetPtr) is abstract; > > end PkgInterface; > > - --- objinterface.ads ------------------------------- > package ObjInterface is > > -- Mon interface class > type MonObjet is interface; > type MonObjetPtr is access all MonObjet; > > end ObjInterface; > > - --- pkgimpl.ads ------------------------------- > with PkgInterface; use PkgInterface; > with ObjInterface; use ObjInterface; > > package PkgImpl is > > type MonImpl is new MonInterface with private; > type MonImplPtr is access all MonImpl; > > overriding > procedure SetObjet(r: in out MonImpl; c: in MonCount; o: in MonObjetPt= r); > > private > > type MonImpl is new MonInterface with record > a: MonObjetPtr; > end record; > > end PkgImpl; > > - --- pkgimpl.adb ------------------------------- > package body PkgImpl is > > procedure SetObjet(r: in out MonImpl; c: in MonCount; o: in > MonObjetPtr) is > begin > r.a :=3D o; > end SetObjet; > > end PkgImpl; > - ---------------------------------- > > When I'm trying to compile pkgimpl.adb I get the following error: > pkgimpl:5:04: (Ada 2005) : abstract interface primitives must be defined > in package specs. > > The interface primitive it's yelling about should be SetObjet which is > correctly defined in the spec. So waht's the matter? It looks like the > MonObjetPtr (access all ObjInterface) is the real problem. > > How can I achieve this? > > Thanks by advance, Well, I've found that if you change type MonObjetPtr is access all MonObjet; to type MonObjetPtr is access all MonObjet'Class; the error goes away. There is no Ada reason why this should be so. I think your program is legal and GNAT has a bug. Maybe it's incorrectly applying a rule for anonymous-access parameters to your MonObjetPtr parameter. But I also see no reason to use "access all MonObjet;" anyway, without the 'Class. Since you can't have objects of type MonObjet, declaring an access to this object (rather than to MonObjet'Class) doesn't seem worthwhile. I think you can make it work by type conversions---you can convert an "access all MonObjet'Class" to an "access all MonObjet" and vice versa, but you can't use an "access all MonObjet" without all those type conversions, so there doesn't seem to be much point in declaring it that way. So that's what I'd do. And the same thing with MonInterfacePtr. By the way, may I make a request of anyone who posts this sort of question? If it involves a GNAT error, please do something extra to indicate what line the error is occurring on. The error message in the post indicated that the error was on line 5, but that's not helpful at all---I can't tell from the post which line is line 5. (For one thing, one of the Ada lines got line-wrapped by my newsreader. For another thing, I can't tell which of the comment lines are actually part of the source file.) Of course, I can figure out what's going on by cutting-and-pasting the source and trying it myself, but that's extra work, plus it's not always feasible if there are missing declarations (e.g. you didn't include the declaration of MonCount in the above source, although that was easy to fix). Maybe this is too much to ask, but I do ask that posters be aware that our newsreaders will not always display the source exactly as your compiler sees it. Thanks. -- Adam