comp.lang.ada
 help / color / mirror / Atom feed
From: "Paweł 'Nivertius' Płazieński" <nivertius@gmail.com>
Subject: Access to function returning class-wide type
Date: Thu, 21 Aug 2008 12:13:10 +0200
Date: 2008-08-21T12:13:10+02:00	[thread overview]
Message-ID: <g8jf3n$e00$1@registered.motzarella.org> (raw)

Hello all.

I'm new here, but I'll try to stick on.

Let me start with a tricky problem:

Consider following code:

----------------------------------------

package A is 
        type Abstracted is abstract tagged null record;
        function Proc (N : Natural) return Abstracted is abstract;

        type The_Access_Type is access function (N : Natural) return
Abstracted'Class;

end A;

-- package A body ommited;

with A;
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 ...'

        function Proc_Wrapper (N : Natural) return Abstracted'Class;

        Working_Object : A.The_Access_Type := B.Proc_Wrapper'Access;
        -- compiler doesn't complain

end B;

package B body is
        function Proc_Wrapper (N : Natural) return Abstracted'Class is
        begin
                return Abstracted'Class'(Proc (N));
        end Proc;

        -- function Proc body ommited
end B;

----------------------------------------

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?

Thanks in advance.

-- 
Paweł Płazieński aka Nivertius
"In the end, there will be Ada, XML and gzip"



             reply	other threads:[~2008-08-21 10:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-21 10:13 Paweł 'Nivertius' Płazieński [this message]
2008-08-21 10:33 ` Access to function returning class-wide type Paweł 'Nivertius' Płazieński
2008-08-21 11:02 ` Dmitry A. Kazakov
2008-08-21 11:56   ` Paweł 'Nivertius' Płazieński
2008-08-21 13:34     ` Dmitry A. Kazakov
2008-08-22  4:53       ` Randy Brukardt
2008-08-22 23:50         ` Randy Brukardt
2008-08-21 12:01 ` Georg Bauhaus
2008-08-21 13:01   ` Paweł 'Nivertius' Płazieński
2008-08-21 13:50     ` Dmitry A. Kazakov
2008-08-21 19:30       ` Paweł 'Nivertius' Płazieński
2008-08-21 20:56         ` Dmitry A. Kazakov
2008-08-22  7:34           ` Paweł 'Nivertius' Płazieński
2008-08-21 17:02 ` Adam Beneschan
2008-08-21 19:22   ` Paweł 'Nivertius' Płazieński
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox