comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.not.jrcarter@acm.not.spam.org>
Subject: Re: Trouble with overriding and class-wide parameters
Date: Sat, 15 Jul 2006 18:52:56 GMT
Date: 2006-07-15T18:52:56+00:00	[thread overview]
Message-ID: <cQaug.838594$084.240400@attbi_s22> (raw)
In-Reply-To: <44b91f16$0$27041$626a54ce@news.free.fr>

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



  parent reply	other threads:[~2006-07-15 18:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-15 17:00 Trouble with overriding and class-wide parameters Yves Bailly
2006-07-15 18:00 ` Dmitry A. Kazakov
2006-07-15 18:20   ` Yves Bailly
2006-07-15 19:12     ` Dmitry A. Kazakov
2006-07-15 18:52 ` Jeffrey R. Carter [this message]
2006-07-15 20:03   ` Yves Bailly
2006-07-16  0:20     ` Jeffrey R. Carter
2006-07-16 10:00 ` Javier Miranda
2006-07-16 12:11   ` Ludovic Brenta
2006-07-16 13:36     ` Javier Miranda
replies disabled

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