From: "Marin David Condic" <marin.condic.auntie.spam@pacemicro.com>
Subject: When to use 'Class in a parameter list
Date: Mon, 23 Jul 2001 16:27:14 -0400
Date: 2001-07-23T20:27:15+00:00 [thread overview]
Message-ID: <9ji1b3$4pi$1@nh.pace.co.uk> (raw)
O.K. Here's something I thought I understood but given behavior of some code
I have, now I'm questioning what is happening.
If I have a tagged type "Base_Type" that has an operation on it, called "Op"
and I derive a new type called "Child_Type" that does not require changes to
"Op", do I make the parameter Base_Type or Base_Type'Class? (My
understanding was that I could make it Base_Type, but then calls to it with
a Child_Type would require explicit type conversion. Making it 'Class would
accept anything of that class without conversion. Apparently the compiler is
swollowing it without type conversion - which is now confusing me.)
In code:
procedure Op (Base : in out Base_Type) ;
...
X : Child_Type ;
...
Op (X) ; -- Why is this working without a Base_Type (X) conversion???
So unless I'm doing something strange that is causing some corner-case to
come up, I'm now wondering why I would need Base_Type'Class as a parameter
type? I was under the impression that I would use 'Class if I wanted to make
an operation that worked on anything derived from the class without explicit
conversion. (Possible to override it in a child class, AFAIK...)
My understanding of when to *NOT* use the 'Class was if I was building an
operation I expected to override (possibly calling the parent operation
within it - using a type conversion). So when it is not overriden, and
control goes to the parent op without an explicit conversion, then when do
you need the 'Class? I must be missing something here......(I need to do
this sort of thing more often - it all evaporates if you don't use it!!!)
MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas www.pacemicro.com
Enabling the digital revolution
e-Mail: marin.condic@pacemicro.com
Web: http://www.mcondic.com/
next reply other threads:[~2001-07-23 20:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-07-23 20:27 Marin David Condic [this message]
2001-07-23 21:39 ` When to use 'Class in a parameter list Ehud Lamm
2001-07-24 12:49 ` Marin David Condic
2001-07-24 14:39 ` Dmitry A. Kazakov
2001-07-24 15:16 ` Ehud Lamm
2001-07-24 17:16 ` Marin David Condic
2001-07-23 22:55 ` Stephen Leake
2001-07-25 19:20 ` Deligation with Ada95 Hans-Olof Danielsson
2001-07-26 2:06 ` Lao Xiao Hai
2001-07-24 2:22 ` When to use 'Class in a parameter list Vincent Marciante
2001-07-24 12:52 ` Marin David Condic
2001-07-24 14:36 ` Ed Falis
2001-07-24 15:29 ` Ehud Lamm
2001-10-29 22:52 ` Matthew Heaney
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox