From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9fb64e4c58f1fe X-Google-Attributes: gid103376,public From: Joerg.Ozimek@t-online.de (Joerg Ozimek) Subject: Re: overload ":=" ??? Date: 1996/07/19 Message-ID: <4snunj$a5d@news00.btx.dtag.de>#1/1 X-Deja-AN: 170533824 references: <31ED3F5F.1135B4EA@jinx.sckans.edu> x-sender: 0823133156-0001@t-online.de (Joerg Ozimek) content-type: text/plain; charset=us-ascii organization: Telekom Online Internet Gateway mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 2.01DT [de] (Win95; I; 16bit) Date: 1996-07-19T00:00:00+00:00 List-Id: David Morton 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