comp.lang.ada
 help / color / mirror / Atom feed
* Access to function returning class-wide type
@ 2008-08-21 10:13 Paweł 'Nivertius' Płazieński
  2008-08-21 10:33 ` Paweł 'Nivertius' Płazieński
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Paweł 'Nivertius' Płazieński @ 2008-08-21 10:13 UTC (permalink / 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"



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2008-08-22 23:50 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-21 10:13 Access to function returning class-wide type Paweł 'Nivertius' Płazieński
2008-08-21 10:33 ` 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

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