From: jimr@col.hp.com (Jim Rogers)
Subject: Please explain why this is wrong...
Date: 7 Feb 1995 23:01:48 GMT
Date: 1995-02-07T23:01:48+00:00 [thread overview]
Message-ID: <3h8u4s$ea3@nonews.col.hp.com> (raw)
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 | |
------------------------------------------------------------------------------
next reply other threads:[~1995-02-07 23:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-02-07 23:01 Jim Rogers [this message]
1995-02-09 3:55 ` Please explain why this is wrong Robert Dewar
1995-02-10 5:19 ` Jim Rogers
[not found] ` <3hjj97$dld@gnat.cs.nyu.edu>
[not found] ` <3hnquq$j2k@watnews1.watson.ibm.com>
[not found] ` <3i3p2q$j7o@gnat.cs.nyu.edu>
1995-02-28 3:54 ` Erik Magnuson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox