Re: An improved Ada?

From: Matthew Heaney (mheaney_at_on2.com)
Date: 09/29/04


Date: Wed, 29 Sep 2004 14:26:30 -0400


"jn" <jonas.nygren@telia.com> wrote in message
news:311c6b78.0409290905.15ae255d@posting.google.com...
>
>
> package A is
> type X is tagged private;
> type Y is new X with private;
> type Z is new X with private;
>
> type X_Ref is access all X'Class;
> type Y_Ref is access all Y'Class;
> type Z_Ref is access all Z'Class;
>
> function X_A (Xa : access X) return Y_Ref;
> function Z_A (Zv : Z) return Y_Ref;
> private
> type X is tagged
> record
> Xr : X_Ref;
> end record;
> type Y is new X with null record;
> type Z is new X with null record;
> end A;
>
> package body A is
> function X_A (Xa : access X) return Y_Ref is
> begin return null; end;
> function Z_A (Zv : Z) return Y_Ref is
> begin return null; end;
> end A;
>
> with A;
> package B is
> type Y is new A.Y with private;
> type Y_Ref is access all Y'Class;
> type Z is new A.Z with private;
>
> function Y_A (
> Ya : access Y )
> return Integer;
> private
> type Y is new A.Y with
> record
> Value : Integer;
> end record;
> type Z is new A.Z with null record;
> end B;
>
> with A;
> with B;
> procedure T is
> Z : B.Z;
> Yr : B.Y_Ref;
> begin
> Yr := B.Y_Ref ( B.Z_A (Z) );
> Yr := B.Y_Ref (A.X_A (A.X_Ref (Yr)));
> -- why not:
> -- Yr := B.Z_A (Z);
> -- B.Y is a descendant of A.Y that is a descendant of A.X
> -- ret value 'tag' could be checked against Yr tag
> -- why don't the compiler do it, why do I have to do it explicitly

Well, obviously this is wrong. Operation B.Z_A returns type A.Y_Ref, not
B.Y_Ref.

> --
> -- why not:
> -- Yr := B.X_A (Yr);
> -- again, B.Y is a descendant of A.Y that is a descendant of A.X
> -- why is not B.X_A visible, X_A should have been inherited
> -- when A.X_A (Yr) is called, why is not the called dispatched?
> -- I have to convert B.Y_Ref to A.X_Ref explicitly
> -- and again I explicitly have to convert return type
> -- from A.X_Ref to B.Y_Ref, a completely safe conversion

Well, obviously this is wrong. There is no operation X_A that returns type
B.Y_Ref declared in package B. You must be confusing this with the
inherited operation X_A that returns type A.Y_Ref.



Relevant Pages

  • Re: Inheritance problem!
    ... but I have a problem with inheritance of the ... The idea of the program is next: we have tagged private types Vector ... package TIO renames Ada.Text_IO; ...
    (comp.lang.ada)
  • Re: Proper program structure
    ... type Car is limited private; ... define each type in a separate package. ... package body Cars.Gear_Box is ...
    (comp.lang.ada)
  • tagged type as generic parameter
    ... type Data is tagged private; -- In order to be able to build lists of items of this type ... package data_handler is ...
    (comp.lang.ada)
  • Re: Indirect visibility of private part in child packages
    ... an indirect visibility of a private part. ... This can be reduced to three package ... conversion) should work, and it's a compiler bug if that is rejected. ... even if the inheritance comes ...
    (comp.lang.ada)
  • OO problem: Performing actions on messages (very long, sorry)
    ... I'm new to Ada. ... action shall override a field in a message. ... package M1_Float_Override_Action is new Action.Override ... type Instance is abstract tagged private; ...
    (comp.lang.ada)