comp.lang.ada
 help / color / mirror / Atom feed
From: Tucker Taft <stt@averstar.com>
Subject: Re: Overloading the assignment operator
Date: Tue, 16 Jan 2001 09:31:39 -0500
Date: 2001-01-16T14:31:39+00:00	[thread overview]
Message-ID: <3A645B4B.3BC177CE@averstar.com> (raw)
In-Reply-To: 92vu8k$epg$1@news.vsnl.net.in

Shankar Narayanan wrote:
> 
> Hello all!
> 
> I'm new to ADA. I'm trying to implement a generic container
> class for a stack which can hold different types of objects using
> a generic type declaration of the form
> 
> generic
>         type data_type is limited private;
> 
> private
>         type node is record
>                 data : data_type;
>                 next : node_ptr;
>         end record;
> 
> I'm using limited private types because they can be used with any
> object (intrinsic or user-defined). The problem is that limited private
> types do not support any of the standard operators (=, /= and :=).
> While I've easily overloaded the = operator (and implicitly the /=),
> I'm not quite able to overload the := (assignment) operator.
> 
> Is it possible to overload the := operator. If so, how?

Not directly, and not for limited types.  You can of course
define your own procedure "Assign" which may be adequate for
most purposes.  However, if you work with non-limited types,
then you can make some or all of the type "controlled" by
deriving it from Ada.Finalization.Controlled.  If you override
the "Adjust" and "Finalize" operation, you indirectly change
the effect of an assignment.  It's somewhat heavy going, so
find a good Ada book, or stick with the simpler "Assign" procedure
approach and limited types.

> Thanks in advance
> Shankar (shanxmail@yahoo.com)

-- 
-Tucker Taft   stt@avercom.net   http://www.averstar.com/~stt/
Chief Technology Officer, AverCom, Inc. (A Titan Company) Burlington, MA  USA
(AverCom was formed 1/1/01 from the Commercial Division of AverStar)
(http://www.averstar.com/services/ebusiness_applications.html)



           reply	other threads:[~2001-01-16 14:31 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <92vu8k$epg$1@news.vsnl.net.in>]
replies disabled

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