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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,100eb0a59892e906,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!k30g2000hse.googlegroups.com!not-for-mail From: Sven Newsgroups: comp.lang.ada Subject: How to pass around access types to interfaces? Date: Fri, 24 Oct 2008 04:45:21 -0700 (PDT) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 93.129.105.10 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1224848722 3749 127.0.0.1 (24 Oct 2008 11:45:22 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 24 Oct 2008 11:45:22 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k30g2000hse.googlegroups.com; posting-host=93.129.105.10; posting-account=oTiqeAoAAAAm9MRakyssPfX9BEL3QpPS User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_5; de-de) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:2484 Date: 2008-10-24T04:45:21-07:00 List-Id: I'm learning Ada and I've run into a big problem with passing around access types to interfaces. I guess I just don't know all the subtleties of access types, I'm used to C/C++ pointers. I didn't find anything helpful on the net or in the Ada Reference Manual. I'm trying to get this code to run: in some package: type My_Interface is interface; type My_Interface_Access is access all My_Interface'Class; procedure Do_Something( Item : in out Some_Object; With : My_Interface_Access ); in main program: type Concrete_Type is new My_Interface with ...; I need to pass an object of type Concrete_Type to the With parameter of the Do_Something procedure. But the Compiler won't let me, no matter what I do. My_Object : access Concrete_Type := new Concrete_Type; Do_Something( Item, My_Interface_Access( My_Object ) ); gives the compiler error "cannot convert local pointer to non-local access type". My_Object : My_Interface_Access := new Concrete_Type; gives the compiler error "type in allocator has deeper level than designated class-wide type". I found a way to pass my paramter by using this function: function Convert( Item : not null access Concrete_Type ) return My_Interface_Access is begin return My_Interface_Access( Item ); end; But I don't this is such a good idea. What is the right way to do this? I can't imagine that what I'm trying to do is not supported in Ada.