comp.lang.ada
 help / color / mirror / Atom feed
From: Xavier Nicollin <Xavier.Nicollin@imag.fr>
Subject: Re: List of packages ?!
Date: Thu, 22 May 2003 18:25:18 +0200
Date: 2003-05-22T18:25:18+02:00	[thread overview]
Message-ID: <3ECCF9EE.A86EAC6B@imag.fr> (raw)
In-Reply-To: 3ECCD541.50200@alcatel.de

Mirko Aigner wrote:
> 
> Hello I am a Student and I got the following problem.
> I got c++ Code and now I should reimplement it in Ada.
> My Problem is: I have a C++ Class only containing methods. In Ada this
> is a package, right ?!

See below.

> In C++ I can create a list containing this methods-only-class,

It's been some time since I last programmed in C++, but I doubt you
can create a list of *class(es)*. I guess you create a list of
*class instances*, that is, a list of objects. So you should do the
same in Ada. Which brings us back to your first question: no, a class
is not a package; a class is a type defined in a package. If it has
only methods, then the record is empty:

package Pack is
   type T is tagged null record; -- could be private
   -- the methods:
   procedure P (X : in T; ...);
   function F (X : T; ...) return ...;
end Pack;

Now, you can create a list of objects of type T, that is, a list
of instances of the class.

Notice that, if your list should contain objects of any "class"
including T and its derivatives, then you need accesses (pointers)
to T'Class (T'Class is the type whose objects are of type T or
of any type derived from T):
   type PT is access all T'Class;
and your list elements are of type PT. I guess this is what you need
(otherwise the list would not be very useful!)

> is that possible for ada, too ?!

Sure, see above.
 
> thanks for the help

You're welcome (in general, and in the Ada world, too).

-- 
| Xavier NICOLLIN (mailto:Xavier.Nicollin@imag.fr) -- INPG (ENSIMAG)
| VERIMAG -- Centre Equation -- 2, ave. de Vignate -- F-38610 Gi�res



  parent reply	other threads:[~2003-05-22 16:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-22 13:48 List of packages ?! Mirko Aigner
2003-05-22 16:24 ` Stephen Leake
2003-05-22 16:25 ` Xavier Nicollin [this message]
2003-05-23  5:07   ` Mirko Aigner
2003-05-22 18:21 ` Noivet
replies disabled

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