comp.lang.ada
 help / color / mirror / Atom feed
From: Steve Vestal <vestal@htc.honeywell.com>
Subject: How do I inherit generic subprograms defined for a parent type?
Date: 13 Aug 2001 15:35:44 -0500
Date: 2001-08-13T15:35:44-05:00	[thread overview]
Message-ID: <vc566britpb.fsf@grinch.htc.honeywell.com> (raw)


I have a type, and some subprograms that operate on objects of that type,
declared in a package specification.

I would like to declare another type as a derivation of that (parent) type.
"Primitive subprograms" are inherited by a derived type from a parent type,
but I can't figure out how to get generic subprograms defined for a parent
type to be inherited as well.

I would be most appreciative of any suggestions.

Here is an example that illustrates my conundrum, with notes on the
complaints raised by gnat 3.13p (look at the comments in Main2).

Steve

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

package Expression is

    type access_expression is private;  -- This will be used as a parent type.

    generic -- How do I get this inherited by a derived type?
        with procedure Data_Operation (D, I: in out integer);
    procedure Generic_Data_Operation (Exp: in access_expression;
                                      Op: in out integer);

private
    type expression is record
        Datum: integer;
    end record;
    type access_expression is access expression;
end Expression;

package body Expression is
    procedure Generic_Data_Operation (Exp: in access_expression;
                                      Op: in out integer) is
    begin
        Data_Operation (Exp.datum, Op);
    end Generic_Data_Operation;
end Expression;

with Expression;
procedure Main2 is

    type access_my_expression is new Expression.access_expression;

    procedure Inc (D, I: in out integer) is
    begin
        D := D + I;
    end Inc;

    -- Alternative 1, Generic_Data_Operation is not visible.  Why isn't
    -- this inherited, it is a subprogram with a parameter of type
    -- access_expression declared in the same package specification?
    procedure Increment is new Generic_Data_Operation (integer, Inc);

    -- Alternative 2 expects Expression.access_expression, not access_my_expression.
    --procedure Increment is new Expression.Generic_Data_Operation (integer, Inc);

    -- I can't declare access_my_expression as a subtype of
    -- Expression.access_expression; in the actual program, it is itself
    -- declared as a private type earlier in a package specification.

    Exp: access_my_expression;

begin
    Increment (Exp, 1);
end Main2;





             reply	other threads:[~2001-08-13 20:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-13 20:35 Steve Vestal [this message]
2001-08-13 21:22 ` How do I inherit generic subprograms defined for a parent type? Ted Dennison
replies disabled

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