Re: Access to function returning class-wide type



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"
.



Relevant Pages

  • Re: view vs. function vs. procedure - really basic question
    ... >>A function can't call a proc but I expect you can rewrite your proc as a ... > For now the workaround is to have the procedure generate a table and ... > use that for the report. ... That rubs me the wrong way but it'll get me ...
    (comp.databases.ms-sqlserver)
  • Re: rake rules with multiple prerequisites
    ... Joel VanderWerf wrote: ... proc and also a FileList? ... as a workaround: ... rake says it doesn't know how to build the task. ...
    (comp.lang.ruby)
  • Re: $0 is truncated
    ... Yukihiro Matsumoto wrote: ... $0 will be updated but the proc title will be truncated to ... that would be my preferred option. ... and only changed it to $0.replaceas a workaround. ...
    (comp.lang.ruby)
  • Re: Eigene SQL Exceptions in einer selbstgeschriebenen Mysql Funktion
    ... Noch nicht erwäht wurde der Workaround, eine nicht existierende Stored ... Proc. ... aufzurufen. ...
    (de.comp.datenbanken.mysql)