comp.lang.ada
 help / color / mirror / Atom feed
* How do I inherit generic subprograms defined for a parent type?
@ 2001-08-13 20:35 Steve Vestal
  2001-08-13 21:22 ` Ted Dennison
  0 siblings, 1 reply; 2+ messages in thread
From: Steve Vestal @ 2001-08-13 20:35 UTC (permalink / 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;





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

* Re: How do I inherit generic subprograms defined for a parent type?
  2001-08-13 20:35 How do I inherit generic subprograms defined for a parent type? Steve Vestal
@ 2001-08-13 21:22 ` Ted Dennison
  0 siblings, 0 replies; 2+ messages in thread
From: Ted Dennison @ 2001-08-13 21:22 UTC (permalink / raw)


In article <vc566britpb.fsf@grinch.htc.honeywell.com>, Steve Vestal says...
>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.
>    type access_expression is private;  -- This will be used as a parent type.
..
>private
>    type expression is record
>        Datum: integer;
>    end record;
>    type access_expression is access expression;
>end Expression;

One thing that strikes me right of the bat is that your "parent type" is not
tagged. If its not tagged, you can still derive from it, but you won't inherit
any operations except the built-in ones (and you won't get most of those on the
outside if you make it "private"). You also won't be able to extend the type in
a derived type by adding new fields and new primitive operations. If that's what
you want, fine, but that's not the impression I got from reading your post.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



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

end of thread, other threads:[~2001-08-13 21:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-13 20:35 How do I inherit generic subprograms defined for a parent type? Steve Vestal
2001-08-13 21:22 ` Ted Dennison

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