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,1e36228aae0595da X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Path: g2news1.google.com!news4.google.com!feeder.news-service.com!news.motzarella.org!motzarella.org!not-for-mail From: =?UTF-8?B?UGF3ZcWCICdOaXZlcnRpdXMnIFDFgmF6aWXFhHNraQ==?= Newsgroups: comp.lang.ada Subject: Re: Access to function returning class-wide type Date: Thu, 21 Aug 2008 13:56:35 +0200 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8Bit X-Trace: feeder.motzarella.org U2FsdGVkX18Uz3WvQRa1ABSdIkTodJP0ZvCm4kRjNmDDJ1Z9o9Ia8FMOysTtOqUAeDyj4AbvzCcaC4X12vGlcHDCM2aSOjQsrPOhLULiysyI2o4I3Bg7MCmoWOuSqfnBRt+TIQ0NNAL/voDshE9ysw== X-Complaints-To: Please send complaints to abuse@motzarella.org with full headers NNTP-Posting-Date: Thu, 21 Aug 2008 11:56:40 +0000 (UTC) X-Auth-Sender: U2FsdGVkX19QMKdmJAWMphk0+uwRtlnYlBs0wB8EqDEB8GvnLzXxJA== Cancel-Lock: sha1:cn5PMg5dSdhyGZ8lrP3zZcEOIkE= User-Agent: KNode/0.10.9 Xref: g2news1.google.com comp.lang.ada:1724 Date: 2008-08-21T13:56:35+02:00 List-Id: Dmitry A. Kazakov wrote: >> What I need is a access type to 'constructor' of an derivate of abstract >> object. >> As I presented, there is a workaround, but that's not the 'right' way to >> do it. I really want to do it without some tricky wrapping. >> How do I define The_Access_Type to do what I want? > See Ada.Tags.Generic_Dispatching_Constructor. It gives you a function > constructing an object from the type tag, the parameters (Natural in your > case) using the function you want (Proc). It goes as follows: > > with Ada.Tags.Generic_Dispatching_Constructor; > package A is > type Abstracted is abstract tagged null record; > function Proc (N : not null access Natural) > return Abstracted is abstract; > function Constructor is > new Ada.Tags.Generic_Dispatching_Constructor > (Abstracted, Natural, Proc); > end A; I belive that would work too, but at the cost of defining function Proc (N : not null access Natural) return ... for each descendant type. That would be another wrapper, so it's the same resolution to the problem as Proc_Wrapper in my original code, assuming that I need Proc (N : Natural) as well. Tell me that I'm wrong, please ;-) -- Paweł Płazieński aka Nivertius "In the end, there will be Ada, XML and gzip"