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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ec7ccf8eee6d37fc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-16 12:43:56 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!news1.rdc1.sfba.home.com.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: virtual functions in ada95 References: <9gg557$8sgga$1@ID-42131.news.dfncis.de> X-Newsreader: Tom's custom newsreader Message-ID: <0GOW6.96902$%i7.71200801@news1.rdc1.sfba.home.com> Date: Sat, 16 Jun 2001 19:43:56 GMT NNTP-Posting-Host: 24.7.82.199 X-Complaints-To: abuse@home.net X-Trace: news1.rdc1.sfba.home.com 992720636 24.7.82.199 (Sat, 16 Jun 2001 12:43:56 PDT) NNTP-Posting-Date: Sat, 16 Jun 2001 12:43:56 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:8810 Date: 2001-06-16T19:43:56+00:00 List-Id: >How can i use virtual functions in Ada? "An Ada dispatching subprogram is analogous to a C++ virtual function." p 27, Ada as a Second Language, ISBN 0-07-011607-5 > type TNTGL_Node_Record is new TNTGL_Custom_Node_Record with private; > type TNTGL_Visual_Node_Record is new TNTGL_Node_Record with private; > type TNTGL_Sphere_Record is new TNTGL_Visual_Node_Record with private; > procedure Run (Node : access TNTGL_Node_Record'Class); > procedure Run (Sphere : access TNTGL_Sphere_Record'Class); A TNTGL_Sphere_Record, or any descendant of one, is also a descendant of TNTL_Node_Record. Which Run would you like to call in that case? I think you want to drop the 'Class from the Run procedure declarations, and have Run dispatch based on the run-time type of its paramter. procedure Run (Node : access TNTGL_Node_Record); procedure Run (Sphere : access TNTGL_Sphere_Record); anything from a TNTGL_Node_Record up to the parent of a TNTGL_Sphere_Record would call the first Run, a Sphere or its descendants would call the second Run.