* Re: Overloading the assignment operator
[not found] <92vu8k$epg$1@news.vsnl.net.in>
@ 2001-01-16 14:31 ` Tucker Taft
0 siblings, 0 replies; only message in thread
From: Tucker Taft @ 2001-01-16 14:31 UTC (permalink / raw)
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)
^ permalink raw reply [flat|nested] only message in thread