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-17 20:24:10 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!cyclone.bc.net!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!news1.sttls1.wa.home.com.POSTED!not-for-mail From: "Mark Lundquist" Newsgroups: comp.lang.ada References: <9gg557$8sgga$1@ID-42131.news.dfncis.de> Subject: Re: virtual functions in ada95 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 Message-ID: Date: Mon, 18 Jun 2001 03:24:09 GMT NNTP-Posting-Host: 24.20.66.39 X-Complaints-To: abuse@home.net X-Trace: news1.sttls1.wa.home.com 992834649 24.20.66.39 (Sun, 17 Jun 2001 20:24:09 PDT) NNTP-Posting-Date: Sun, 17 Jun 2001 20:24:09 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:8827 Date: 2001-06-18T03:24:09+00:00 List-Id: "Thomas Nebel" wrote in message news:9gg557$8sgga$1@ID-42131.news.dfncis.de... > Hi > > How can i use virtual functions in Ada? I have a superclass and some classes > that are derived > from it: > > type TNTGL_Custom_Node_Record is tagged null record; > 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; > > type TNTGL_Node is access all TNTGL_Node_Record'Class; > type TNTGL_Sphere is access all TNTGL_Sphere_Record'Class; > .... > procedure Run (Node : access TNTGL_Node_Record'Class); > procedure Run (Node : access TNTGL_Group_Node_Record'Class); > procedure Run (Sphere : access TNTGL_Sphere_Record'Class); OK... don't declare the parameters to the Run subprograms to have classwide types. You want them to be primitive to these types. A classwide parameters says "here is something for me, and also anything derived from me", i.e. it applies across the derivation class. (I'm assuming you realize that Ada uses the word "class" to mean something completely different than what it means to the rest of the OOPL world...). Now, there _is_ a connection between classwide types and dispatching... Specifically, dispatching oocurs only if you have an actual parameter of a classwide type matched with a formal parameter that is of a specific type. Also... what's the rationale for using access parameters to Run rather than 'in' or 'in out' parameters? Just curious... Hope this keps, - mark