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-Thread: 103376,87cefb21a3c43af8 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns13feed!worldnet.att.net!attbi_s22.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Trouble with overriding and class-wide parameters References: <44b91f16$0$27041$626a54ce@news.free.fr> In-Reply-To: <44b91f16$0$27041$626a54ce@news.free.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 12.201.97.176 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s22 1152989576 12.201.97.176 (Sat, 15 Jul 2006 18:52:56 GMT) NNTP-Posting-Date: Sat, 15 Jul 2006 18:52:56 GMT Date: Sat, 15 Jul 2006 18:52:56 GMT Xref: g2news2.google.com comp.lang.ada:5710 Date: 2006-07-15T18:52:56+00:00 List-Id: Yves Bailly wrote: > > package Pkg is > type Some_Type is tagged null record; > not overriding > procedure Setup(st: not null access Some_Type; > p : access Some_Type'Class); > end Pkg; > > with Pkg; use Pkg; > package Sub_Pkg is > type Sub_Type is new Some_Type with null record; > not overriding > procedure Setup(st: not null access Sub_Type; > p : access Sub_Type'Class); > end Sub_Pkg; Note that Sub_Type is not a subtype. Sub_Pkg defines 2 procedures named Setup: 1. Implicitly, from the primitive Setup for Some_Type, with "not null access Sub_Type" and "access Some_Type'Class". The implementation of this is identical to the implementation of Pkg.Setup. 2. Explicitly, "not null access Sub_Type" and "access Sub_Type'Class", since it's "not overriding". > with Pkg; use Pkg; > with Sub_Pkg; use Sub_Pkg; > procedure Test is > st: aliased Sub_Type; > begin > st.Setup(null); > end Test; I would expect this to be ambiguous, since it matches the profile for both of the Setup procedures. If I'm correct, this would be a compiler error. > Sorry in advance if it's a silly question, I have a huge background > of C++ and not yet very skilled with Ada type system. In the C/++ mind set, it's common to have visible pointers and pointer parameters all over the place. In the Ada mind set, access types, parameters, and values are avoided whenever possible, and hidden when not. This isolates memory management, making memory-management errors easier to find, and usually makes the package easier for the client to use. It's rare, in a well designed Ada system, to have access types/values/parameters in package specifications. There's probably a way to design your system to avoid having access parameters in the specs. As an Ada beginner, you will probably find it valuable to avoid "use" clauses. This may seem like more work, but you will learn useful things that way. In this case, you have no need for Pkg at all, and so should not even "with" it; typing "Sub_Pkg." in the declaration of St is actually less work than typing " use Sub_Pkg;". -- Jeff Carter "Sir Robin the-not-quite-so-brave-as-Sir-Lancelot, who had nearly fought the Dragon of Angnor, who nearly stood up to the vicious Chicken of Bristol, and who had personally wet himself at the Battle of Badon Hill." Monty Python & the Holy Grail 68