comp.lang.ada
 help / color / mirror / Atom feed
* Overriding puzzle
@ 2015-12-30 14:49 gautier_niouzes
  2015-12-30 15:10 ` Egil H H
  0 siblings, 1 reply; 12+ messages in thread
From: gautier_niouzes @ 2015-12-30 14:49 UTC (permalink / 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;

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-01-03  7:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-30 14:49 Overriding puzzle gautier_niouzes
2015-12-30 15:10 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox