comp.lang.ada
 help / color / mirror / Atom feed
From: Joerg.Ozimek@t-online.de (Joerg Ozimek)
Subject: Re: overload ":=" ???
Date: 1996/07/19
Date: 1996-07-19T00:00:00+00:00	[thread overview]
Message-ID: <4snunj$a5d@news00.btx.dtag.de> (raw)
In-Reply-To: 31ED3F5F.1135B4EA@jinx.sckans.edu


David Morton <dmorton@jinx.sckans.edu> wrote:
>> Is there a way to overload the assignment operator ":=" ?


The language (-> LRM 4.5) defines only the following six categories of
operators. The corresponding operator_symbols, and only those, can be
used as designators in declarations of functions for user-defined
operators. 

  logical_operator            ::=  and | or  | xor
  relational_operator         ::=  =   | /=  | <   | <= | > | >=
  binary_adding_operator      ::=  +   | -   | &
  unary_adding_operator       ::=  +   | -
  multiplying_operator        ::=  *   | /   | mod | rem
  highest_precedence_operator ::=  **


Therefore the assignment_statement ":=" is not an operator and 
can't be overloaded! :-((


But you have the ability to control the effects of an assignement by
inheriting your own "controlled type" from the private tagged type
Controlled. You find it in the predefined package Ada.Finalization 
(-> LRM 7.6).

----------------------------------------------------
with Ada.Finalization;
use  Ada.Finalization;
package MyText is
   type Text is new Controlled with private;
   procedure Adjust (Object : in out Text);
private
   type Text is new Controlled with
      record
         Buffer : String(1..50);
         Length : Natural := 0;
      end record;
end MyText;
----------------------------------------------------
with Ada.Text_IO;
use  Ada.Text_IO;
package body MyText is
   procedure Adjust (Object : in out Text) is
   begin
      Put_Line ("Here is the text : " & 
                Object.Buffer(1 .. Object.Length));
      -- here you can place some usefull control code,
      -- which is executed after an assignement ...
   end Adjust;
end MyText;
----------------------------------------------------



Joerg Ozimek





      parent reply	other threads:[~1996-07-19  0:00 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-17  0:00 overload ":=" ??? David Morton
1996-07-17  0:00 ` Robert Dewar
1996-07-18  0:00   ` Laurent Guerby
1996-07-18  0:00   ` David Morton
1996-07-19  0:00     ` David Weller
1996-07-19  0:00     ` Brad Balfour
1996-07-25  0:00   ` Wolfgang Gellerich
1996-07-25  0:00     ` Robert A Duff
1996-07-18  0:00 ` John Herro
1996-07-18  0:00   ` Robert Dewar
1996-07-19  0:00     ` John Herro
1996-07-21  0:00       ` David Morton
1996-07-21  0:00       ` Laurent Guerby
1996-07-22  0:00         ` Robert A Duff
1996-07-23  0:00           ` Laurent Guerby
1996-07-23  0:00             ` John Herro
1996-07-23  0:00             ` Robert A Duff
1996-07-22  0:00       ` David Morton
1996-07-22  0:00         ` Robert Dewar
1996-07-23  0:00         ` Robert A Duff
1996-07-22  0:00           ` Robert Dewar
1996-07-22  0:00       ` Laurent Guerby
1996-07-22  0:00       ` Laurent Guerby
1996-07-23  0:00       ` Tarjei Jensen
1996-07-23  0:00         ` Robert A Duff
1996-07-24  0:00       ` Robert I. Eachus
1996-07-18  0:00 ` Jon S Anthony
1996-07-19  0:00 ` Joerg Ozimek [this message]
replies disabled

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