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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7a8e90e9b8a62d13,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-02-07 15:04:12 PST Path: swrinde!sdd.hp.com!hplabs!hplextra!news.dtc.hp.com!col.hp.com!jimr From: jimr@col.hp.com (Jim Rogers) Newsgroups: comp.lang.ada Subject: Please explain why this is wrong... Date: 7 Feb 1995 23:01:48 GMT Organization: HP Colorado Springs Division Message-ID: <3h8u4s$ea3@nonews.col.hp.com> NNTP-Posting-Host: hpsqe4.col.hp.com X-Newsreader: TIN [version 1.2 PL2] Date: 1995-02-07T23:01:48+00:00 List-Id: I have been playing with simple inheritance models. When I try to declare a type as: type Cube is new Square with null record; I get the following message from the gnatf tool: shapes.ads:87:09: type must be declared abstract or else "new_square" overriden Why do I get this message. I think I am using the same syntax I read in the Instr.ads file found in the GNAT examples directory. The source for my code follows: -- file shapes.ads ----------------------------------------------------------------------------- -- Experimenting with the simple designs of Ada shapes classes ----------------------------------------------------------------------------- with Ada.Numerics.Aux; use Ada.Numerics.Aux; package shapes is ----------------------------------------------------------------------------- -- Abstract definition for shape ----------------------------------------------------------------------------- type shape is abstract tagged private; function area( Object : shape) return double is abstract; function get_name( Object : shape ) return string is abstract; ----------------------------------------------------------------------------- -- Definition of rectangle as an inheritor of shape ----------------------------------------------------------------------------- type rectangle is new shape with private; function new_rectangle( height : double; width : double ) return rectangle; function area ( Object : rectangle ) return double; function get_name (Object : rectangle ) return string; ----------------------------------------------------------------------------- -- Definition of circle as an inheritor of shape ----------------------------------------------------------------------------- type circle is new shape with private; function new_circle( Radius : double ) return circle; function area ( Object : circle ) return double; function get_name ( Object : circle ) return string; ----------------------------------------------------------------------------- -- Definition of square as an inheritor of rectangle ----------------------------------------------------------------------------- type square is new shape with private; function new_square ( Side : double ) return square; function area ( Object : square ) return double; function get_name ( Object : square ) return string; ----------------------------------------------------------------------------- -- Definition of square as an inheritor of rectangle ----------------------------------------------------------------------------- type cube is new square with private; function new_cube (Side : double) return cube; function volume ( Object : cube ) return double; function get_name ( Object : cube ) return string; private type shape is tagged null record; type rectangle is new shape with record height : double := 0.0; width : double := 0.0; end record; type circle is new shape with record radius : double := 0.0; end record; type square is new shape with record side : double := 0.0; end record; type cube is new square with null record; end shapes; -- file shapes.adb with Ada.Numerics.Aux; use Ada.Numerics.Aux; package body shapes is function new_rectangle( height : double; width : double ) return rectangle is tmp : rectangle; begin tmp.height := height; tmp.width := width; return tmp; end new_rectangle; function area ( Object : rectangle ) return double is begin return Object.height * Object.width; end area; function get_name (Object : rectangle ) return string is begin return "rectangle"; end get_name; function new_circle( Radius : double ) return circle is tmp : circle; begin tmp.radius := radius; return tmp; end new_circle; function area ( Object : circle ) return double is begin return double(3.14159) * Object.radius * Object.radius; end area; function get_name ( Object : circle ) return string is begin return "circle"; end get_name; function new_square ( Side : double ) return square is tmp : square; begin tmp.side := side; return tmp; end new_square; function area ( Object : square ) return double is begin return Object.side * Object.side; end area; function get_name ( Object : square ) return string is begin return "square"; end get_name; function new_cube ( Side : double ) return cube is tmp : cube; begin tmp.side := side; return tmp; end new_cube; function volume ( Object : cube ) return double is S : double := Object.side; begin return S * S * S; end volume; function get_name ( Object : cube ) return string is begin return "cube"; end get_name; end shapes; -- ------------------------------------------------------------------------------ | Jim Rogers | Dead Reckoning: | | Hewlett-Packard Company | Traditional form of rough-estimate | | Colorado Springs Division | navigation used for hundreds of years by | | | sailors, almost all of whom are dead. | | jimr@col.hp.com | | ------------------------------------------------------------------------------