From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b74ec64483660e21 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-07-24 09:01:29 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!feed.textport.net!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: When to use 'Class in a parameter list Date: 23 Jul 2001 18:55:09 -0400 Organization: NASA Goddard Space Flight Center Message-ID: References: <9ji1b3$4pi$1@nh.pace.co.uk> NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 995929949 7139 128.183.220.71 (23 Jul 2001 23:12:29 GMT) X-Complaints-To: dscoggin@cne-odin.gsfc.nasa.gov NNTP-Posting-Date: 23 Jul 2001 23:12:29 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.6 Xref: archiver1.google.com comp.lang.ada:10524 Date: 2001-07-23T23:12:29+00:00 List-Id: "Marin David Condic" writes: > O.K. Here's something I thought I understood but given behavior of some code > I have, now I'm questioning what is happening. > > > > In code: > > procedure Op (Base : in out Base_Type) ; > ... just for clarity: type Child_Type is new Base_Type; > X : Child_Type ; > ... > Op (X) ; -- Why is this working without a Base_Type (X) > conversion??? Because when you declare a derived type (Child_Type), you implicitly declare all the 'primitive operations' of the parent type, for the child type. So you now have: procedure Op (Base : in out Child_Type); This is the whole idea of derived types; it is important to understand this feature. > 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. Yes, this is true. > (Possible to override it in a child class, AFAIK...) I'm not clear what you mean by this. If you declare: procedure Class_Wide_Op (Foo : in Base_Type'class); then it is _not_ a 'primitive operation', since the type of the argument is _not_ 'Base_Type' (Base_type'class is a _different_ type!). Only 'primitive operations' can be overridden in derived types. > 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!!!) Hmm. When you do not explicitly override Op, the implicitly declared operation gets an implicit body that is the same as the parent body. Another difference between a 'Class parameter and a plain parameter; when you call a primitive operation with a 'Class value, you get run-time dynamic dispatching. When you call a primitive operation with a plain value, you get compile-time static dispatching. I'm not clear if this matters in your case. -- -- Stephe