comp.lang.ada
 help / color / mirror / Atom feed
* Q: How to inherit methods from parent tagged object?
@ 2020-05-21 13:23 Warren
  2020-05-21 13:50 ` Jere
  0 siblings, 1 reply; 3+ messages in thread
From: Warren @ 2020-05-21 13:23 UTC (permalink / raw)


I've become rusty and am refreshing myself with Ada again using a pet project..

I have a tagged class that I want to inherit all but one of the methods for:

   type Flash is new Emulator.Memory.Flash with private;
   
   procedure Initialize(Obj: in out Flash);
--   function Fetch(Obj: in out Flash; Address: Address_Type) return Word_Type;
--   function First_Address(Obj: in Flash) return Address_Type;
--   function Last_Address(Obj: in Flash) return Address_Type;

The only thing I want to override in the new object is the Initialize procedure for the new object. There must be a way to specify that but I can't seem to goggle it on the interwebs. Every example I can find completely redefines all of the methods.  

I'd like to avoid re-specifying the bodies of Fetch, First_Address and Last_Address for the new object, if that is permitted.  If memory serves, there is a way... but the worms have invaded my brain.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Q: How to inherit methods from parent tagged object?
  2020-05-21 13:23 Q: How to inherit methods from parent tagged object? Warren
@ 2020-05-21 13:50 ` Jere
  2020-05-21 14:20   ` Warren
  0 siblings, 1 reply; 3+ messages in thread
From: Jere @ 2020-05-21 13:50 UTC (permalink / raw)


On Thursday, May 21, 2020 at 9:23:52 AM UTC-4, Warren wrote:
> I've become rusty and am refreshing myself with Ada again using a pet project..
> 
> I have a tagged class that I want to inherit all but one of the methods for:
> 
>    type Flash is new Emulator.Memory.Flash with private;
>    
>    procedure Initialize(Obj: in out Flash);
> --   function Fetch(Obj: in out Flash; Address: Address_Type) return Word_Type;
> --   function First_Address(Obj: in Flash) return Address_Type;
> --   function Last_Address(Obj: in Flash) return Address_Type;
> 
> The only thing I want to override in the new object is the Initialize procedure for the new object. There must be a way to specify that but I can't seem to goggle it on the interwebs. Every example I can find completely redefines all of the methods.  
> 
> I'd like to avoid re-specifying the bodies of Fetch, First_Address and Last_Address for the new object, if that is permitted.  If memory serves, there is a way... but the worms have invaded my brain.

I feel like you are either leaving out some other info about
Emulator.Memory.Flash or I am just completely misunderstanding.
If you only want to override Initialize, then just do that:

   type Flash is new Emulator.Memory.Flash with private;
   overriding procedure Initialize(Obj: in out Flash);

The "overriding" keyword is optional but good practice.  Doing this
will override Initialize but not the other operations.  If this
doesn't work you need to tell us more about any errors you are
encountering.  Note that this is true for almost all languages
that support inheritance, you just override the operations you want 
to and the rest will just use the baseclass version.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Q: How to inherit methods from parent tagged object?
  2020-05-21 13:50 ` Jere
@ 2020-05-21 14:20   ` Warren
  0 siblings, 0 replies; 3+ messages in thread
From: Warren @ 2020-05-21 14:20 UTC (permalink / raw)


On Thursday, 21 May 2020 09:50:24 UTC-4, Jere  wrote:
> On Thursday, May 21, 2020 at 9:23:52 AM UTC-4, Warren wrote:
> > I've become rusty and am refreshing myself with Ada again using a pet project..
> > 
> > I have a tagged class that I want to inherit all but one of the methods for:
> > 
> >    type Flash is new Emulator.Memory.Flash with private;
> >    
> >    procedure Initialize(Obj: in out Flash);
> > --   function Fetch(Obj: in out Flash; Address: Address_Type) return Word_Type;
> > --   function First_Address(Obj: in Flash) return Address_Type;
> > --   function Last_Address(Obj: in Flash) return Address_Type;
> > 
> > The only thing I want to override in the new object is the Initialize procedure for the new object. There must be a way to specify that but I can't seem to goggle it on the interwebs. Every example I can find completely redefines all of the methods.  
> > 
> > I'd like to avoid re-specifying the bodies of Fetch, First_Address and Last_Address for the new object, if that is permitted.  If memory serves, there is a way... but the worms have invaded my brain.
> 
> I feel like you are either leaving out some other info about
> Emulator.Memory.Flash or I am just completely misunderstanding.
> If you only want to override Initialize, then just do that:
> 
>    type Flash is new Emulator.Memory.Flash with private;
>    overriding procedure Initialize(Obj: in out Flash);
> 
> The "overriding" keyword is optional but good practice.  Doing this
> will override Initialize but not the other operations.  If this
> doesn't work you need to tell us more about any errors you are
> encountering.  Note that this is true for almost all languages
> that support inheritance, you just override the operations you want 
> to and the rest will just use the baseclass version.

When I just try to override Initialize, I get the error:

emulator-memory-attiny13.ads:46:09: missing full declaration for private extension

Arrrg, I found the problem.. and am embarrassed to say, I was missing the:

  type Flash is new Emulator.Memory.Flash with null record;

in the private section. DOH!

Thanks for your time.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-21 14:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-21 13:23 Q: How to inherit methods from parent tagged object? Warren
2020-05-21 13:50 ` Jere
2020-05-21 14:20   ` Warren

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