comp.lang.ada
 help / color / mirror / Atom feed
From: johnherro@aol.com (John Herro)
Subject: Re: overload ":=" ???
Date: 1996/07/18
Date: 1996-07-18T00:00:00+00:00	[thread overview]
Message-ID: <4smd11$5bl@newsbf02.news.aol.com> (raw)
In-Reply-To: 31ED3F5F.1135B4EA@jinx.sckans.edu


David Morton <dmorton@jinx.sckans.edu> writes:
>Is there a way to overload the assignment operator ":=" ?
     Unfortunately, no.  However, you can write your own procedure Assign
or Set.  The difficulty with that is that you may forget to call it, and
use the predefined := instead.
     The workaround is to make the type of the object you're assigning
limited private.  Then the compiler will force you to call your Set
procedure, and won't allow you accidentally to use := (outside the
package).  For example:

package P is
   type Stack is limited private;
   ...
   procedure Set (Left: out Stack; To: in Stack);
end P;

with P; use P;
procedure Main is
   A, B : Stack;
   ...
begin
   ...
   Set(A, To => B); -- Legal
   A := B; -- Illegal.  Compiler will catch this.
end Main;
     There's more information about when to use private types and when to
use limited private types in my Ada Tutor program.  I hope this helps.
- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor




  parent reply	other threads:[~1996-07-18  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   ` David Morton
1996-07-19  0:00     ` Brad Balfour
1996-07-19  0:00     ` David Weller
1996-07-18  0:00   ` Laurent Guerby
1996-07-25  0:00   ` Wolfgang Gellerich
1996-07-25  0:00     ` Robert A Duff
1996-07-18  0:00 ` John Herro [this message]
1996-07-18  0:00   ` Robert Dewar
1996-07-19  0:00     ` John Herro
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             ` Robert A Duff
1996-07-23  0:00             ` John Herro
1996-07-21  0:00       ` David Morton
1996-07-22  0:00       ` Laurent Guerby
1996-07-22  0:00       ` Laurent Guerby
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-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
replies disabled

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