comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@cs.nyu.edu (Robert Dewar)
Subject: Re: Please explain why this is wrong...
Date: 8 Feb 1995 22:55:15 -0500
Date: 1995-02-08T22:55:15-05:00	[thread overview]
Message-ID: <3hc3n3$onc@gnat.cs.nyu.edu> (raw)
In-Reply-To: 3h8u4s$ea3@nonews.col.hp.com

Your program is clearly wrong, and the message from GNAT is quite precise.

You have a primitive operation New_Square, which is inherited when you
make a rectangle to give a function New_Square that returns a Rectangle.

Now it is not clear why you made this a primitive operation. I rather suspect
that you expect to use New_Square only for a Square, in which case it should
NOT be primitive.

If indeed you intend it to be inherited, it MUST be overridden. The reason
for this rule is simple. In the general case the derivation involves extending
the type, and how could the original function code possibly know enough to
initialize the extension -- it couldn't.

If as I suspect, you really did not intend New_Square to be inherited, but
rather intended it to serve as a constructor only for the Square case, then
you must be sure that you do not declare in as being primitive. The easiest
way to declare non-primitive operations is to nest them in a subpackages;

   package Constructors is
      function New_Square .. return Square;
   end Constructors;




  reply	other threads:[~1995-02-09  3:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-02-07 23:01 Please explain why this is wrong Jim Rogers
1995-02-09  3:55 ` Robert Dewar [this message]
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