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,1e36228aae0595da X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Path: g2news1.google.com!news2.google.com!news4.google.com!feeder.news-service.com!feeder6.cambrium.nl!feed.tweaknews.nl!xlned.com!feeder1.xlned.com!news-out1.kabelfoon.nl!newsfeed.kabelfoon.nl!bandi.nntp.kabelfoon.nl!transit5.hitnews.eu!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Thu, 21 Aug 2008 14:01:38 +0200 From: Georg Bauhaus User-Agent: Thunderbird 2.0.0.16 (Macintosh/20080707) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Access to function returning class-wide type References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-ID: <48ad5922$0$20706$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 21 Aug 2008 14:01:38 CEST NNTP-Posting-Host: 7cf6fd63.newsspool4.arcor-online.net X-Trace: DXC=C`KJ16H@7GTV0Pe9PRnbJ\4IUK\BH3YRmb Paweł 'Nivertius' Płazieński schrieb: > package B is > type Derived is new A.Abstracted with null record; > function Proc (N : Natural) return Derived; > > Failing_Object : A.The_Access_Type := B.Proc'Access; > -- will not compile, error: 'expected type The_Access_Type / found type > access function Proc defined at ...' (Compiler is right because the profile of B.Proc is different from that of The_Access_Type (whose functions return Abstracted'Class, not Derived) In general, public access types lead to unneccessary complication; tagged types are by reference already, so you could simply use dispatching and a factory instead. Do you have spefific needs for pointers to functions returning by-reference objects? Or follow Dmitry's advice. package A is type Abstracted is abstract tagged null record; function Proc (N : Natural) return Abstracted is abstract; package Constructor is No_Suitable_Type: exception; function Proc_Wrapper(N : Natural) return Abstracted'Class; -- create objects of types in Abstracted'Class; the -- specific type depends on N and other things that are -- in scope in Constructor's body end Constructor; end A; with A; package B is type Derived is new A.Abstracted with null record; overriding function Proc (N : Natural) return Derived; end B; package body A is package body Constructor is function Proc_Wrapper(N : Natural) return Abstracted'Class is begin if N > 666 then -- and possibly Some_Other_Condition ... declare use B; begin return Derived'(Proc(N)); end; else -- -- other cases TBD -- raise No_Suitable_Type; end if; end Proc_Wrapper; end Constructor; end A; package body B is function Proc (N : Natural) return Derived is begin return Derived'(null record); end Proc; end B; HTH -- Georg Bauhaus Y A Time Drain http://www.9toX.de