comp.lang.ada
 help / color / mirror / Atom feed
From: Gene Ouye <geneo@rational.com>
Subject: Re: on OO differnces between Ada95 and C++
Date: 1996/02/22
Date: 1996-02-22T00:00:00+00:00	[thread overview]
Message-ID: <NEWTNews.825015458.26661.geneo@medusa.ppp.rational.com> (raw)
In-Reply-To: Dn4J2F.uI@bton.ac.uk


John English <je@bton.ac.uk> wrote:
  [...]
> If the spec of Saving_Account has "with Account" at the beginning,
> "with Saving_Account" will imply "with Account". 

This is not true.  In order to compile and link the entire 
application, if you have a module "X" that with's Saving_Account, 
then X is indirectly dependent on Account (ie, you can't link X 
without having Account already compiled), but there is no implicit 
"with" that is included.  The with clause means you have visibility 
to declarations in referenced unit, in the above example, X, by 
withing Saving_Account has visibility to Saving_Account declaration, 
but NOT to Account declarations.

However, Saving_Account, because it with'ed Account, does have 
visibility to Account declarations.

> Or use child  packages: make Saving_Account a child of Account (e.g. 
> Account.Saving)  so that it is effectively an extension of Account.

This is true (as many others have demonstrated in this thread).

  [...]
> You can always put "subtype Money_Type is Account.Money_Type" in
> Saving_Account to make it directly usable from Saving_Account...

Yes, you can do this, but it probably won't do what I think you 
were intending.  You will have a Saving_Account.Money_Type that is
visible, but the values of the subtype may not be visible (if it's
numeric, then the numeric literals are directly convertible, but
if it's, say, an enumeration type, the enumeration literals aren't
made directly visible by a subtype declaration).  In any case, 
numeric type or no, the operations aren't brought along with a 
subtype declaration.  So you could assign numeric literals to 
objects of the subtype Saving_Account.Money_Type, but you couldn't 
invoke any operations on objects of that type unless you somehow
got visibility to them in Account (where they are declared).

Many have posted ways for this to be done, so there's no need for
me to get into them here...

If you're interested in religious language flame wars, you could
say that this is a case where Ada doesn't to what is expected.  But
if you understand what the subtype declaration really does, then this 
behavior really should be expected.  In other words, whether you're
doing C++ or Ada, you can't expect the language subtleties to be 
"expected" unless you get some education.

Gene Ouye <geneo@rational.com>






  parent reply	other threads:[~1996-02-22  0:00 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-02-20  0:00 on OO differnces between Ada95 and C++ Nasser Abbasi
1996-02-20  0:00 ` Robert I. Eachus
1996-02-20  0:00 ` Jerome Desquilbet
1996-02-21  0:00   ` Robert Dewar
1996-02-22  0:00     ` Jerome Desquilbet
1996-02-24  0:00       ` Robert Dewar
1996-02-22  0:00   ` Pete Becker
1996-02-23  0:00     ` Jerome Desquilbet
1996-02-26  0:00     ` Darren C Davenport
1996-02-26  0:00       ` Pete Becker
1996-02-27  0:00         ` Nigel Perry
1996-02-20  0:00 ` Norman H. Cohen
1996-02-21  0:00   ` Mark A Biggar
1996-02-22  0:00     ` Norman H. Cohen
1996-02-27  0:00   ` Adam Morris
1996-02-21  0:00 ` Darren C Davenport
1996-02-21  0:00 ` Jon S Anthony
1996-02-21  0:00 ` John English
1996-02-22  0:00   ` Nasser Abbasi
1996-02-26  0:00     ` John English
1996-02-27  0:00       ` Dale Stanbrough
1996-02-22  0:00   ` Gene Ouye [this message]
1996-02-26  0:00     ` John English
  -- strict thread matches above, loose matches on Subject: below --
1996-02-21  0:00 Christian Jaensch, FRG
1996-02-26  0:00 Simon Johnston
replies disabled

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