18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

192 Child libraries<br />

Another generic procedure G_3Order can be written which will order its three parameters. This new procedure<br />

uses an <strong>in</strong>stantiation of the procedure G_Order <strong>in</strong>ternally.<br />

generic<br />

--Specification<br />

type T is ( ); --Any discrete type<br />

procedure G_3Order( A,B,C:<strong>in</strong> out T ); --Prototype ord<br />

with G_Order;<br />

procedure G_3Order( A,B,C:<strong>in</strong> out T ) is --Implementation ord<br />

procedure Order is new G_Order( T ); --Instantiate order<br />

beg<strong>in</strong><br />

Order( A, B ); --S L -<br />

Order( B, C );<br />

--? ? L<br />

Order( A, B );<br />

--S M L<br />

end G_3Order; --<br />

Note:<br />

The generic parameter T can only be a member of the discrete types. This is achieved with the<br />

declaration of the type T as ‘type T is ()’.<br />

The procedure order <strong>in</strong> the procedure G_3Order is an <strong>in</strong>stantiation of the generic procedure<br />

G_Order with an actual parameter of type T.<br />

Figure 14.1 illustrates the components of a generic procedure.<br />

Specification of<br />

generic procedure<br />

Generic<br />

type T is ( );<br />

The formal type specifies the<br />

category of types to which the<br />

generic parameter can belong<br />

procedure G_Order( A,B:<strong>in</strong> out T );<br />

Implementation of<br />

generic procedure<br />

procedure G_Order( A,B:<strong>in</strong> out T ) is<br />

Tmp : T;<br />

beg<strong>in</strong><br />

-- Code of generic procedure<br />

end G_Order;<br />

Figure 14.1 Components of a generic procedure declaration.<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!