comp.lang.ada
 help / color / mirror / Atom feed
* Tagged types (beginner's question) !
@ 2002-08-29  9:39 Vincent DIEMUNSCH
  2002-08-30 13:35 ` Ted Dennison
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Vincent DIEMUNSCH @ 2002-08-29  9:39 UTC (permalink / raw)


Hello,

I have a simple question concerning tagged types. Suppose that we have :

    type Rationnel is abstract new Ada.Finalization.Controlled with null
record;

    type Fraction is new Rationnel with record
          Num�rateur    : integer;
          D�nominateur : positive;
       end record;

    type Entier is new Fraction with null record;

First Question :
    Can I override the primitive operation "Adjust" of the controlled
type with the following :
        procedure Adjust (F : in out Fraction'Class);
    instead of :
        procedure Adjust( F : in out Fraction);

Second question :
    How can Adjust (F : in out Fraction'Class) return an object of type
Entier instead of Fraction ?
    I tried something like
        F := E; --(with E : Entier)
    and many other more complicated things but I always have the same
error message from GNAT :
        "Dynamiclly tagged expression required".

Looking in the ARM and the user guide from GNAT, I could not get what
this message meant !
Any help would be greatly appreciated. Thanks in advance.

Vincent DIEMUNSCH







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

* Re: Tagged types (beginner's question) !
  2002-08-29  9:39 Tagged types (beginner's question) ! Vincent DIEMUNSCH
@ 2002-08-30 13:35 ` Ted Dennison
  2002-08-30 14:31 ` Pat Rogers
  2002-08-30 16:04 ` Stephen Leake
  2 siblings, 0 replies; 4+ messages in thread
From: Ted Dennison @ 2002-08-30 13:35 UTC (permalink / raw)


Vincent DIEMUNSCH <"vincent.diemunsch"@edf.fr@NO.SPAM.PLEASE> wrote in message news:<akkq54$kcq$1@clnews.edf.fr>...

>     and many other more complicated things but I always have the same
> error message from GNAT :
>         "Dynamiclly tagged expression required".

This message generally means that the expression in question needs to
have to have a 'Class in it somewhere.



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

* Re: Tagged types (beginner's question) !
  2002-08-29  9:39 Tagged types (beginner's question) ! Vincent DIEMUNSCH
  2002-08-30 13:35 ` Ted Dennison
@ 2002-08-30 14:31 ` Pat Rogers
  2002-08-30 16:04 ` Stephen Leake
  2 siblings, 0 replies; 4+ messages in thread
From: Pat Rogers @ 2002-08-30 14:31 UTC (permalink / raw)


> First Question :
>     Can I override the primitive operation "Adjust" of the
controlled
> type with the following :
>         procedure Adjust (F : in out Fraction'Class);
>     instead of :
>         procedure Adjust( F : in out Fraction);

No.  That would be a different procedure and not an overriding.

> Second question :
>     How can Adjust (F : in out Fraction'Class) return an object of
type
> Entier instead of Fraction ?
>     I tried something like
>         F := E; --(with E : Entier)
>     and many other more complicated things but I always have the
same
> error message from GNAT :
>         "Dynamiclly tagged expression required".

Better deal with the problem above first.





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

* Re: Tagged types (beginner's question) !
  2002-08-29  9:39 Tagged types (beginner's question) ! Vincent DIEMUNSCH
  2002-08-30 13:35 ` Ted Dennison
  2002-08-30 14:31 ` Pat Rogers
@ 2002-08-30 16:04 ` Stephen Leake
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Leake @ 2002-08-30 16:04 UTC (permalink / raw)


Vincent DIEMUNSCH <"vincent.diemunsch"@edf.fr@NO.SPAM.PLEASE> writes:

> Hello,
> 
> I have a simple question concerning tagged types. Suppose that we have :
> 
>     type Rationnel is abstract new Ada.Finalization.Controlled with null
> record;
> 
>     type Fraction is new Rationnel with record
>           Num�rateur    : integer;
>           D�nominateur : positive;
>        end record;
> 
>     type Entier is new Fraction with null record;
> 
> First Question :
>     Can I override the primitive operation "Adjust" of the controlled
> type with the following :
>         procedure Adjust (F : in out Fraction'Class);
>     instead of :
>         procedure Adjust( F : in out Fraction);

No. This would be "overloading", not "overriding". Calls to Adjust on
an object of type Rationnel or Fraction made by the run-time system
will not dispatch to this procedure.

Adjust has a very specific meaning for Controlled types. Why do you
want to do this instead?

> Second question : How can Adjust (F : in out Fraction'Class) return
> an object of type Entier instead of Fraction ? 

Note that Adjust is a procedure, so it does not "return" anything. Not
clear what you really mean here.

Again, why do you want to do this? 

If you are trying to emulate C++ constructors (just a wild guess), try
defining:

function New_Entier (...) return Entier;

-- 
-- Stephe



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

end of thread, other threads:[~2002-08-30 16:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-29  9:39 Tagged types (beginner's question) ! Vincent DIEMUNSCH
2002-08-30 13:35 ` Ted Dennison
2002-08-30 14:31 ` Pat Rogers
2002-08-30 16:04 ` Stephen Leake

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