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,100eb0a59892e906 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!uio.no!fi.sn.net!newsfeed1.fi.sn.net!news.song.fi!not-for-mail Date: Fri, 24 Oct 2008 15:24:50 +0300 From: Niklas Holsti User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20060628 Debian/1.7.8-1sarge7.1 X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: How to pass around access types to interfaces? References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4901be81$0$23607$4f793bc4@news.tdc.fi> Organization: TDC Internet Services NNTP-Posting-Host: laku61.adsl.netsonic.fi X-Trace: 1224851073 news.tdc.fi 23607 81.17.205.61:32852 X-Complaints-To: abuse@tdcnet.fi Xref: g2news1.google.com comp.lang.ada:2485 Date: 2008-10-24T15:24:50+03:00 List-Id: Sven wrote: > 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 assume this type declaration is in the main *procedure*. This means that the type has a local scope and life, which prevents converting its values to a more long-lived access type. Try declaring Concrete_Type in a package; that makes it live as long as the whole program, and should allow such conversions. HTH, -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .