TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Christoph & Ursula Grein <[log in to unmask]>
Reply To:
Christoph & Ursula Grein <[log in to unmask]>
Date:
Thu, 20 May 1999 15:58:38 +0200
Content-Type:
text/plain
Parts/Attachments:
text/plain (65 lines)
What is the difference between declaring overriding operations in the visible
part and declaring them in the private part?

Consider the following example:
----------------
package Class is

  type Root is tagged null record;

  procedure Operation (R : in Root);

  type Derived is new Root with null record;

  -- procedure Operation (D : in Derived);  -- overrides

private

  procedure Operation (D : in Derived);  -- overrides

end Class;
-----------------
with Ada.Text_Io;
use  Ada.Text_Io;

package body Class is

  procedure Operation (R : in Root) is
  begin
    Put_Line ("Root");
  end Operation;

  procedure Operation (D : in Derived) is
  begin
    Put_Line ("Derived");
  end Operation;

end Class;
-----------------
with Class;
use  Class;

procedure Tester is

  R : Root;
  D : Derived;

begin

  -- no dispatching calls
  Operation (R);  -- visible
  Operation (D);  -- derived, invisibly overridden

end Tester;
-------------------
The specific operation for object Derived is inherited and invisibly overridden.

Why does this work? What is the difference to overriding it in the visible part?
Please enlighten me.

Christoph Grein
Member of Ada Germany

http://home.T-Online.de/home/Christ-Usch.Grein
[log in to unmask]

ATOM RSS1 RSS2