From: EMANUELE COSTA <e.costa@LANCASTER.AC.UK>
Subject: Generic Types and Packages in Ada, C++ , Java
Date: 1997/02/26
Date: 1997-02-26T00:00:00+00:00 [thread overview]
Message-ID: <Pine.SOL.3.91.970226205433.1179A-100000@unixc.lancs.ac.uk> (raw)
Hi all,
If there is something I really like about Ada are the generic
packages, but now I have to write some stuff in C++ and Java and so I would
like to know if there is such a thing in these languages.
Example:
assuming a Generic Stack
-----
generic
type object_type is private;
max_size :natural:=100;
package stack_package is
stack_full :exception;
stack_empty :exception;
procedure push(the_Object :object_type);
function pop return object_type;
function number_of_objects return natural;
end stack_package;
package body stack_package is
subtype count is natural range 0..max_size;
subtype index is positive range 1..max_size;
type array_of_objects is array (index) of object_type;
latest :count:=0;
objects :array_of_objects;
procedure push(the_object :object_type) is
begin
latest:=latest+1;
Objects(latest):=the_object;
exception
...
...
finally in order to create an instance
e.g. stack of integers
package stack_1 is new stack_package(integer,50)
-----
COuld anyone mail two similar packages in C++ and Ada?
Thank you
EMANUELE
--
e-mail: costa@unix.lancs.ac.uk
Jenkinson's Law: It Won't Work.
Support your local rescue centre: GET LOST!
SUPPORT 'PADANIA LIBERA' CAMPAIGN: www.leganordsen.it
reply other threads:[~1997-02-26 0:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox