TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy


Options: Use Classic View

Use Proportional Font
Show HTML Part by Default
Show All Mail Headers

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

Print Reply
Christoph & Ursula Grein <[log in to unmask]>
Thu, 20 May 1999 15:58:38 +0200
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


  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
    Put_Line ("Root");
  end Operation;

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

end Class;
with Class;
use  Class;

procedure Tester is

  R : Root;
  D : Derived;


  -- 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
[log in to unmask]