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,51890d5f6003bad4 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Integer'Class Date: Tue, 5 Oct 2004 10:45:01 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de HY/omDJRbGN7P+5ELEZxGgksklffM0yIU8UgpSIZwcrI1YN9s= User-Agent: 40tude_Dialog/2.0.12.1 Xref: g2news1.google.com comp.lang.ada:4719 Date: 2004-10-05T10:45:01+02:00 List-Id: 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 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 ; -- 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