comp.lang.ada
 help / color / mirror / Atom feed
* Two class-wide operands, but only one controlling
@ 2002-11-23 16:10 Victor Porton
  2002-11-23 19:50 ` Pascal Obry
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Victor Porton @ 2002-11-23 16:10 UTC (permalink / raw)


I want something like a procedure with two class-wide operands,
(of two different types) but only one of these controlling.

The solution I found is introducing new tagged record
types which would refer to these two types and passing both
operands as one operand in such the record. Other solutions?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Two class-wide operands, but only one controlling
  2002-11-23 16:10 Two class-wide operands, but only one controlling Victor Porton
@ 2002-11-23 19:50 ` Pascal Obry
  2002-11-24  8:27 ` Victor Porton
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Pascal Obry @ 2002-11-23 19:50 UTC (permalink / raw)



porton@ex-code.com (Victor Porton) writes:

> I want something like a procedure with two class-wide operands,
> (of two different types) but only one of these controlling.
> 
> The solution I found is introducing new tagged record
> types which would refer to these two types and passing both
> operands as one operand in such the record. Other solutions?

Declare the second one as a class-wide ('Class) parameter.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Two class-wide operands, but only one controlling
  2002-11-23 16:10 Two class-wide operands, but only one controlling Victor Porton
  2002-11-23 19:50 ` Pascal Obry
@ 2002-11-24  8:27 ` Victor Porton
  2002-11-24  8:59   ` Samuel Tardieu
  2002-11-24 11:34 ` Victor Porton
  2002-11-25 19:19 ` Matthew Heaney
  3 siblings, 1 reply; 9+ messages in thread
From: Victor Porton @ 2002-11-24  8:27 UTC (permalink / raw)


In article <ubs4gvzea.fsf@wanadoo.fr>,
	Pascal Obry <p.obry@wanadoo.fr> writes:
> porton@ex-code.com (Victor Porton) writes:
> 
>> I want something like a procedure with two class-wide operands,
>> (of two different types) but only one of these controlling.
>> 
>> The solution I found is introducing new tagged record
>> types which would refer to these two types and passing both
>> operands as one operand in such the record. Other solutions?
> 
> Declare the second one as a class-wide ('Class) parameter.

What?! It is clearly stated that I want _both_ of them
class wide...



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Two class-wide operands, but only one controlling
  2002-11-24  8:27 ` Victor Porton
@ 2002-11-24  8:59   ` Samuel Tardieu
  0 siblings, 0 replies; 9+ messages in thread
From: Samuel Tardieu @ 2002-11-24  8:59 UTC (permalink / raw)


>>>>> "Victor" == Victor Porton <porton@ex-code.com> writes:

Victor> In article <ubs4gvzea.fsf@wanadoo.fr>,
Victor> 	Pascal Obry <p.obry@wanadoo.fr> writes:
>> porton@ex-code.com (Victor Porton) writes:
>>
>>> I want something like a procedure with two class-wide operands,
>>> (of two different types) but only one of these controlling.
>>>
>>> The solution I found is introducing new tagged record types which
>>> would refer to these two types and passing both operands as one
>>> operand in such the record. Other solutions?
>>
>> Declare the second one as a class-wide ('Class) parameter.

Victor> What?! It is clearly stated that I want _both_ of them class
Victor> wide...

I think you are confusing actual (in the call) and formal (in the
declaration) parameters. Pascal proposes that you use a first
non-class-wide formal parameter and a second class-wide formal
parameter.

The actual parameter of a class-wide formal parameter cannot be a
controlling operand.

  Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/sam



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Two class-wide operands, but only one controlling
  2002-11-23 16:10 Two class-wide operands, but only one controlling Victor Porton
  2002-11-23 19:50 ` Pascal Obry
  2002-11-24  8:27 ` Victor Porton
@ 2002-11-24 11:34 ` Victor Porton
  2002-11-24 21:56   ` Pascal Obry
                     ` (2 more replies)
  2002-11-25 19:19 ` Matthew Heaney
  3 siblings, 3 replies; 9+ messages in thread
From: Victor Porton @ 2002-11-24 11:34 UTC (permalink / raw)


In article <877kf34a3t.fsf@inf.enst.fr>,
	Samuel Tardieu <sam@rfc1149.net> writes:
>>>>>> "Victor" == Victor Porton <porton@ex-code.com> writes:
> 
> Victor> In article <ubs4gvzea.fsf@wanadoo.fr>,
> Victor> 	Pascal Obry <p.obry@wanadoo.fr> writes:
>>> porton@ex-code.com (Victor Porton) writes:
>>>
>>>> I want something like a procedure with two class-wide operands,
>>>> (of two different types) but only one of these controlling.
>>>>
>>>> The solution I found is introducing new tagged record types which
>>>> would refer to these two types and passing both operands as one
>>>> operand in such the record. Other solutions?
>>>
>>> Declare the second one as a class-wide ('Class) parameter.
> 
> Victor> What?! It is clearly stated that I want _both_ of them class
> Victor> wide...
> 
> I think you are confusing actual (in the call) and formal (in the
> declaration) parameters. Pascal proposes that you use a first
> non-class-wide formal parameter and a second class-wide formal
> parameter.

Not what I need. basically I have a container and an iterator.
Both a derived (in my case I need this) from abstract container
and abstract iterator. I need procedure like:

procedure Next
  (C: Abstract_Container'Class; I: in out Abstract_Iterator'Class);
  
but this is an error as we have two controlling operands of
different types :-( I cannot make one of these non class-wide
as both a abstract.

It was simple in C++. Ada has disadvantages...

> The actual parameter of a class-wide formal parameter cannot be a
> controlling operand.

Samuel, di you meant vice versa?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Two class-wide operands, but only one controlling
  2002-11-24 11:34 ` Victor Porton
@ 2002-11-24 21:56   ` Pascal Obry
  2002-11-25 22:17   ` Matthew Heaney
  2002-11-27 17:25   ` Matthew Heaney
  2 siblings, 0 replies; 9+ messages in thread
From: Pascal Obry @ 2002-11-24 21:56 UTC (permalink / raw)



porton@ex-code.com (Victor Porton) writes:

> Not what I need. basically I have a container and an iterator.
> Both a derived (in my case I need this) from abstract container
> and abstract iterator. I need procedure like:
> 
> procedure Next
>   (C: Abstract_Container'Class; I: in out Abstract_Iterator'Class);
>   
> but this is an error as we have two controlling operands of
> different types :-( 

Certainly not. 'Class formal parameters are not controlling operands, your
Next procedure above is perfectly legal.

> It was simple in C++. Ada has disadvantages...

No, you misunderstood Ada :)

> > The actual parameter of a class-wide formal parameter cannot be a
> > controlling operand.
> 
> Samuel, di you meant vice versa?

No, we have be 2 of us saying the same thing but you did not listen :)

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Two class-wide operands, but only one controlling
  2002-11-23 16:10 Two class-wide operands, but only one controlling Victor Porton
                   ` (2 preceding siblings ...)
  2002-11-24 11:34 ` Victor Porton
@ 2002-11-25 19:19 ` Matthew Heaney
  3 siblings, 0 replies; 9+ messages in thread
From: Matthew Heaney @ 2002-11-25 19:19 UTC (permalink / raw)


porton@ex-code.com (Victor Porton) wrote in message news:<3ddfa8b8$0$304$bed64819@news.gradwell.net>...
> I want something like a procedure with two class-wide operands,
> (of two different types) but only one of these controlling.
> 
> The solution I found is introducing new tagged record
> types which would refer to these two types and passing both
> operands as one operand in such the record. Other solutions?

No, you don't need two separate types.  Just declare the second
parameter as type T'Class, e.g.

   type T is tagged ...;

   procedure Op (O1 : T; O2 : T'Class);

Now procedure Op only dispatches according to the tag of O1.

If you want two separate types, then just do this:

   procedure Op (O1 : T; O2 : T2'Class);



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Two class-wide operands, but only one controlling
  2002-11-24 11:34 ` Victor Porton
  2002-11-24 21:56   ` Pascal Obry
@ 2002-11-25 22:17   ` Matthew Heaney
  2002-11-27 17:25   ` Matthew Heaney
  2 siblings, 0 replies; 9+ messages in thread
From: Matthew Heaney @ 2002-11-25 22:17 UTC (permalink / raw)


porton@ex-code.com (Victor Porton) wrote in message news:<3de0b9be$0$304$bed64819@news.gradwell.net>...
> 
> Not what I need. basically I have a container and an iterator.
> Both a derived (in my case I need this) from abstract container
> and abstract iterator. I need procedure like:
> 
> procedure Next
>   (C: Abstract_Container'Class; I: in out Abstract_Iterator'Class);
>   
> but this is an error as we have two controlling operands of
> different types :-( I cannot make one of these non class-wide
> as both a abstract.
> 
> It was simple in C++. Ada has disadvantages...

Whatever you can do in C++, you can also do in Ada.

Post the C++ code (or just email it do me), and we'll see if we can't
figure out what the real problem is.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Two class-wide operands, but only one controlling
  2002-11-24 11:34 ` Victor Porton
  2002-11-24 21:56   ` Pascal Obry
  2002-11-25 22:17   ` Matthew Heaney
@ 2002-11-27 17:25   ` Matthew Heaney
  2 siblings, 0 replies; 9+ messages in thread
From: Matthew Heaney @ 2002-11-27 17:25 UTC (permalink / raw)


porton@ex-code.com (Victor Porton) wrote in message news:<3de0b9be$0$304$bed64819@news.gradwell.net>...
> 
> Not what I need. basically I have a container and an iterator.
> Both a derived (in my case I need this) from abstract container
> and abstract iterator. I need procedure like:
> 
> procedure Next
>   (C: Abstract_Container'Class; I: in out Abstract_Iterator'Class);
>   
> but this is an error as we have two controlling operands of
> different types :-( I cannot make one of these non class-wide
> as both a abstract.
> 
> It was simple in C++. Ada has disadvantages...

A virtual function can only be a class member function, which means it
can be virtual for only one class.

Either you have this:

class Container
{
public:
   class Iterator { ... };

   virtual void next(Iterator&) const = 0;
...
};

Or you have this:

class Container
{
public:
   class Iterator 
   {
   public:
      virtual void next(const Container&) = 0;
      ...
   };
...
};


Both of which have a trivial conversion to Ada95.  So what is the
problem, exactly?



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2002-11-27 17:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-23 16:10 Two class-wide operands, but only one controlling Victor Porton
2002-11-23 19:50 ` Pascal Obry
2002-11-24  8:27 ` Victor Porton
2002-11-24  8:59   ` Samuel Tardieu
2002-11-24 11:34 ` Victor Porton
2002-11-24 21:56   ` Pascal Obry
2002-11-25 22:17   ` Matthew Heaney
2002-11-27 17:25   ` Matthew Heaney
2002-11-25 19:19 ` Matthew Heaney

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