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-Thread: 103376,7137ee7358078d09 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!news.glorb.com!news.ecp.fr!news.in2p3.fr!in2p3.fr!kanaga.switch.ch!news-zh.switch.ch!switch.ch!cernne03.cern.ch!cern.ch!news From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Basic Explaination of OO in Ada Date: Wed, 20 Sep 2006 09:16:22 +0200 Organization: CERN - European Laboratory for Particle Physics Message-ID: References: <1158593087.194781.250030@e3g2000cwe.googlegroups.com> <1158636734.971377.112550@d34g2000cwd.googlegroups.com> <1158674185.887102.205150@m73g2000cwd.googlegroups.com> <1158679879.965952.156540@m73g2000cwd.googlegroups.com> NNTP-Posting-Host: abpc10883.cern.ch Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sunnews.cern.ch 1158736583 10076 (None) 137.138.37.241 X-Complaints-To: news@sunnews.cern.ch User-Agent: Thunderbird 1.5.0.5 (X11/20060801) In-Reply-To: <1158679879.965952.156540@m73g2000cwd.googlegroups.com> Xref: g2news2.google.com comp.lang.ada:6681 Date: 2006-09-20T09:16:22+02:00 List-Id: Ludovic Brenta wrote: > Here's another interesting tip for C++ programmers. In C++, once you > declare a member function to be "virtual", all calls to that member > function dispatch dynamically, across the entire program. Except when you ask it otherwise by qualifying the function name at the call site, see below. > Conversely, > if a member function lacks the "virtual" keyword, calls to it are > always static. The only way you can determine whether calls dispatch > statically or dynamically is by looking at the declaration of the > member function. Things can become quite nasty if a class overrides an > inherited, non-virtual member function, and makes it virtual. Yes, it becomes nasty. It's a classical no-no for C++ programmers. > I'm not > even sure what the language rules are in this case. The static type used to call determines whether it dispatches or not, because it's the static type (of the pointer or reference) that allows to check whether the function is virtual. > In contrast, in Ada, you do not declare primitive operations as > "virtual", or "dynamic" or whatever. Instead, you choose *at the point > of call* whether or not the call dispatches. Consider: > > with Pak; use Pak; > procedure Test (Object : in out T'Class) is > begin > P (Object); -- dynamic dispatch > P (T (Object)); -- view conversion to a specific type => static > dispatch > end Test; Similar for C++: p->fun(); // dynamic dispatch if in *p fun is virtual p->BaseClass::fun(); // no dynamic dispatch -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/