comp.lang.ada
 help / color / mirror / Atom feed
From: je@bton.ac.uk (John English)
Subject: Re: Tagged types and static dispatching
Date: 1996/12/05
Date: 1996-12-05T00:00:00+00:00	[thread overview]
Message-ID: <586rp8$l9o@saturn.brighton.ac.uk> (raw)
In-Reply-To: 32A2E972.28AF@masda.hv.se


Tobias Ritzau (Tobias.Ritzau@masda.hv.se) wrote:
: I have some trouble understanding some featers of Ada 95. I wrote a
: small package with a linked list and a list iterator. Of course I wanted
: the types to be tagged so that I could expand them later on. When I
: compiled my package I got an error message saying:
:   operation can be displatching in only one type

Yes, since you have the two tagged types declared in the same pacakge
spec, you're asking the compiler is trying to make Restart a primitive
operation of *both* types.

Possible solutions:
1) Make ListIt non-tagged, so Restart only has one tagged parameter and
   so is only a primitive of List (as you found out)
2) Use a class-wide parameter so again Restart has only one tagged
   parameter and is only a primitive of List
3) Declare the types in different package specifications so Restart
   is only a primitive of the type declared in the same specification.

The advantage of (2) is that you can do double dispatching (selecting
a primitive operation based on two independent tagged values) like so:

  procedure Restart(I : in out ListIt'Class; L : in List) is
     -- calls dispatch to the appropriate version of Restart depending
     -- on the actual type of L
  begin
     ListIt_Primitive(I);	-- dispatches to the appropriate
				-- ListIt operation depending on
				-- the actual type of I
  end Restart;
---------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.comp.it.bton.ac.uk/je
 Dept. of Computing        | fax: (+44) 1273 642405
 University of Brighton    |
---------------------------------------------------------------




      parent reply	other threads:[~1996-12-05  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-12-02  0:00 Tagged types and static dispatching Tobias Ritzau
1996-12-02  0:00 ` Paul Chardon
1996-12-05  0:00 ` John English [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