comp.lang.ada
 help / color / mirror / Atom feed
* How to check class type ?
@ 2021-04-21 17:08 DrPi
  2021-04-21 17:26 ` AdaMagica
  2021-04-21 17:40 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 7+ messages in thread
From: DrPi @ 2021-04-21 17:08 UTC (permalink / raw)


Hi,

I have the following declarations (just for the example) :

type Root is tagged null record;
type Root_Ptr is access all Root'Class;

type Leaf1 is new Root with null record;
type Leaf1_Ptr is access all Leaf1'Class;

type Leaf2 is new Root with null record;
type Leaf2_Ptr is access all Leaf2'Class;


To check if a variable is of type Leaf1_Ptr or Leaf2_Ptr, I do :
if var'Tag = Leaf1'Tag then
    ...
elsif var'Tag = Leaf2'Tag then
    ...
end if;

It works. But is this correct ? Should the test be done differently to 
suit Ada coding style ?

Nicolas

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

end of thread, other threads:[~2021-04-23 16:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-21 17:08 How to check class type ? DrPi
2021-04-21 17:26 ` AdaMagica
2021-04-21 17:33   ` DrPi
2021-04-21 17:48   ` DrPi
2021-04-23 16:13     ` John McCabe
2021-04-21 17:40 ` Dmitry A. Kazakov
2021-04-22  8:50   ` DrPi

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