comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Integer'Class
Date: Tue, 5 Oct 2004 10:45:01 +0200
Date: 2004-10-05T10:45:01+02:00	[thread overview]
Message-ID: <m4rvn8xikzaz.19capus9cq86x$.dlg@40tude.net> (raw)
In-Reply-To: cjsoqg$re7$04$1@news.t-online.com

On Tue, 5 Oct 2004 02:10:55 +0200, Rick Santa-Cruz wrote:

> sorry for so many questions.... maybe that's easy to answer, but I don't 
> find any senseful answer to that:
> Why can't I use: Integer'Class, but I can derive a new class from Integer in 
> writing:
> type New_Int is new Integer range 1..100;
> 
> Isn't this unlogical? Or have I missunderstand something completly?

Not at all. It is quite logical, all types should have T'Class, (probably
T'Class ones too (:-)). But when Ada 83 was extended to Ada 95, a decision
was taken not to go that far. I suppose, because the amount of changes
needed was considered too large. So only tagged types may be grouped in
classes, presently. Constructors/destructors were implemented as a hack
etc. Alas.

As for New_Int, it is not just deriving from Integer. It is something like:

-- This is not Ada!
type <Anonymous_Subtype> is -- Deriving a subtype
   new Integer
      with null record              -- No extension
      with constraint range 1..100; -- Constraint on the values
type New_Int is new <Anonymous_Subtype>; -- Cloning the subtype

The result is a clone of a subtype of Integer. It is an unrelated to
Integer type. Therefore it cannot be put into Integer'Class, it induces a
class of its own. A related construct is:

subtype Sub_Int is Integer range 1..100;

This only puts a constraint, but produces no true new type. So you cannot
override Integer operations in Sub_Int, only overload (with nasty
consequences). This is a heavy heritage of Ada 83, which considered all
subtypes as constrained bases.

I do hope that Ada 2010 will have T'Class for all specific types, let's
see.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2004-10-05  8:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-05  0:10 Integer'Class Rick Santa-Cruz
2004-10-05  0:52 ` Integer'Class Jeffrey Carter
2004-10-05  1:00   ` Integer'Class Rick Santa-Cruz
2004-10-05 19:45     ` Integer'Class Jeffrey Carter
2004-10-05  7:16 ` Integer'Class Martin Krischik
2004-10-05 19:49   ` Integer'Class Jeffrey Carter
2004-10-05  8:45 ` Dmitry A. Kazakov [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-10-05  7:35 Integer'Class Christoph Karl Walter Grein
replies disabled

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