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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d7cc034a367221eb X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-02-05 23:59:44 PST Path: supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!195.54.122.107!newsfeed1.bredband.com!bredband!newsfeed1.telenordia.se!algonet!uab.ericsson.se!erinews.ericsson.se!news.emw.ericsson.se!not-for-mail Message-ID: <3A7FAEEE.8B49DDA3@emw.ericsson.se> From: Sven Nilsson Reply-To: sven.nilsson@emw.ericsson.se Organization: Ericsson Microwave Systems AB X-Mailer: Mozilla 4.75C-EMW [en] (X11; U; SunOS 5.7 sun4u) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: accessing subprogram & inheritance problem References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Tue, 06 Feb 2001 08:59:42 +0100 NNTP-Posting-Host: 136.225.182.69 X-Trace: news.emw.ericsson.se 981446382 136.225.182.69 (Tue, 06 Feb 2001 08:59:42 MET) NNTP-Posting-Date: Tue, 06 Feb 2001 08:59:42 MET Xref: supernews.google.com comp.lang.ada:4962 Date: 2001-02-06T08:59:42+01:00 List-Id: tmoran@acm.org wrote: > > >I would like to have a subprogram pointer in the root class which > >can be used to point to the subprograms in the child class as well. > As a general rule, if Ada makes it hard to do something one way, > it's a good bet there are problems that way, and there is a better > approach. > In this case, why not just use dispatching, or even just overloading, > to call the right ..._Action routine, rather than futz about with > a pointer? Exactly! This seems to be a very common misstake made by newcomers to Ada. Pretty much everytime we have a new programmer working with us, he or she will eventually come with this exact question. The answer is always: "Don't do that". I don't really know if you CAN do it, but I do know you shouldn't. Instead overloading is the way to go. You should always call the child first, which in turn may call the more general implementation of the parent. If you design your code properly and think OO all the way, this shouldn't be a problem. Your exampel (that's Vicky's example) is a bit confusing. I looks pretty much like C in Ada-syntax. That's not good. You should be doing something like this: with Text_Io; procedure Mytest is package Root is type Root_T is tagged record -- Whatever! null; end record; procedure Do_Action(Object : in Root_T); end Root; package body Root is procedure Do_Action(Object : in Root_T) is begin text_io.put_line("Root Action"); end Do_Action; end Root; use Root; package Child is type Child_T is new Root_T with null record; procedure Do_Action(Object : in Child_T); end Child; package body Child is procedure Do_Action(Object : Child_T) is begin Text_Io.Put_Line("Calling parent:"); Do_Action(Root_T(Object)); Text_Io.Put_Line("Back again!"); text_io.put_line("Child Action"); end Do_Action; end Child; use Child; Root_Object : Root_T; Child_Object : Child_T; begin Do_Action(Root_Object); Do_Action(Child_Object); end Mytest;