From: gautier_niouzes@hotmail.com
Subject: Overriding puzzle
Date: Wed, 30 Dec 2015 06:49:10 -0800 (PST)
Date: 2015-12-30T06:49:10-08:00 [thread overview]
Message-ID: <5be84c5a-9614-4ee2-ae85-beb962171a05@googlegroups.com> (raw)
Hello,
A small puzzle for year end...
I have a type A and a derived type Custom. How should I redesign things such that a call to New_Page (for an object of type Custom) displays "This is a custom header" and not "This is a normal header", in the code below ?
TIA for your help!...
_________________________
Gautier's Ada programming
http://sf.net/users/gdemont/
--8<---------8<---------8<---------8<-------
with Ada.Text_IO; use Ada.Text_IO;
procedure Test_override is
package Pkg is
type A is tagged null record;
procedure Header(o: A);
procedure New_Page(o: A);
end;
package body Pkg is
procedure Header(o: A) is
pragma Unreferenced (o);
begin
Put_Line("This is a normal header");
end;
procedure New_Page(o: A) is
begin
Header(o);
end;
end;
type Custom is new Pkg.A with null record;
overriding procedure Header(o: Custom) is
pragma Unreferenced (o);
begin
Put_Line("This is a custom header");
end;
obj: Custom;
begin
obj.New_Page;
end;
next reply other threads:[~2015-12-30 14:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-30 14:49 gautier_niouzes [this message]
2015-12-30 15:10 ` Overriding puzzle Egil H H
2015-12-30 17:31 ` gautier_niouzes
2015-12-30 18:07 ` marciant
2015-12-30 18:24 ` gautier_niouzes
2015-12-30 21:40 ` marciant
2015-12-30 23:10 ` Randy Brukardt
2015-12-31 8:22 ` Niklas Holsti
2015-12-31 8:42 ` Dmitry A. Kazakov
2016-01-03 7:18 ` Randy Brukardt
2015-12-31 16:30 ` marciant
2015-12-30 23:13 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox