comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Polymorphism
Date: Thu, 07 May 2015 08:28:45 +0100
Date: 2015-05-07T08:28:45+01:00	[thread overview]
Message-ID: <lysib8zw0i.fsf@pushface.org> (raw)
In-Reply-To: da4139a7-d66a-4153-a68f-7eca4c8982b0@googlegroups.com

slos <new.stephane.los@gmail.com> writes:

> I'd like function Object.Area to stay private but the compiler doesn't
> see it like that and complains if I try to move it in the private
> part.

If you do that, the compiler says

slos.ada:24:13: this primitive operation is declared too late
slos.ada:24:13: abstract subprograms must be visible (RM 3.9.3(10))

The reason for this is that derived types wouldn't know that they needed
to implement the abstract operations.

If you make the private subprogram concrete,

   function Area (O : Instance) return Float
     is (raise Program_Error with "Area not implemented");

then Circle.Area isn't overriding (because Object.Area isn't visible).

If you make Circle a child of Object (package Object.Circle), all is
OK. This is of curse rather restrictive; it depends on who you want to
be able to derive from Object.Instance.


The workround I adopted in a similar situation was to comment the
subprograms that had to be visible with "private use only". I think now
I would make the names obviously logically private
(e.g. "Private_Area").


  reply	other threads:[~2015-05-07  7:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-06 23:05 Polymorphism slos
2015-05-07  7:28 ` Simon Wright [this message]
2015-05-07  8:32   ` Polymorphism slos
2015-05-07  7:41 ` Polymorphism Dmitry A. Kazakov
2015-05-07  8:34   ` Polymorphism slos
2015-05-07 19:09   ` Polymorphism Randy Brukardt
2015-05-11 22:05     ` Polymorphism slos
2015-05-12  1:29       ` Polymorphism Randy Brukardt
2015-05-14 21:34         ` Polymorphism slos
  -- strict thread matches above, loose matches on Subject: below --
1996-11-25  0:00 polymorphism W. Wesley Groleau (Wes)
replies disabled

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