From: "Rick Santa-Cruz" <rick_santa_cruz75@msn.com>
Subject: Re: implicit cast and inheritance
Date: Sat, 2 Oct 2004 18:32:04 +0200
Date: 2004-10-02T18:32:04+02:00 [thread overview]
Message-ID: <cjml6p$n6l$03$1@news.t-online.com> (raw)
In-Reply-To: mailman.154.1096675788.390.comp.lang.ada@ada-france.org
Hi,
>> I have a small question. See the following source-code:
>> package Pack is
>> type Base is tagged
>> record
>> Value: Integer;
>> end record;
>> procedure Base_Proc(B: Base);
>>
>> type Derived is new Base with
>> null record;
>> end Pack;
>>
>> And now I have the following source for the main-procedure:
>> with Pack;
>> use Pack;
>>
>> procedure main is
>> B: Base;
>> D: Derived;
>> procedure Proc(B: Base) is
>> begin
>> null;
>> end Proc;
>> begin
>> Pack.Base_Proc(B); -- 1
>> Pack.Base_Proc(D); -- 2
>> Proc(B); -- 3
>> Proc(D); -- 4
>> end main;
>>
>
> In this case, there is one compiled version of the body of Base_Proc,
> and the call Base_Proc (D) calls it. D is passed by reference, so the
> body doesn't know or care whether it is getting a Base type or a
> Derived type.
So an implict cast will be done from Derived to Base, so that the body of
the Base_Proc(B: Base) method can be called. Is this correct?
You told me, that in the package the following will be declared:
procedure Base_Proc (B : Derived);
But what's then with the body of Pack? Will there be an body of Base_Proc(B:
Derived) which is the same as Base_Proc(B: Base), or how does it work?
>> If it is in the same package, is then always implicitly done a cast,
>> or is the procedure Base_Proc in the derived class "Derived"
>> automatically defined with a parameter Type "Derived"?
>
> There is a difference between declaring a subprogram and providing an
> implementation for it.
Sadly, I don't understand what you mean with this.
Thanks in advance,
Rick
next prev parent reply other threads:[~2004-10-02 16:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-01 20:50 implicit cast and inheritance Rick Santa-Cruz
2004-10-02 0:09 ` Stephen Leake
2004-10-02 16:32 ` Rick Santa-Cruz [this message]
2004-10-02 21:35 ` Stephen Leake
2004-10-02 22:05 ` Rick Santa-Cruz
2004-10-03 10:23 ` Marius Amado Alves
2004-10-03 13:27 ` CBFalconer
2004-10-03 12:32 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox