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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,56131a5c3acc678e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-08 05:25:51 PST Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!newshosting.com!news-xfer2.atl.newshosting.com!news-feed01.roc.ny.frontiernet.net!nntp.frontiernet.net!uunet.MISMATCH!ash.uu.net!spool.news.uu.net!not-for-mail Date: Mon, 08 Dec 2003 08:25:42 -0500 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5) Gecko/20031013 Thunderbird/0.3 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Question about OO programming in Ada References: <5JmdnUF_9o_ABE-iRTvUrg@rapidnet.com> <1273941.m4G3ZzughP@linux1.krischik.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Message-ID: <1070889942.156714@master.nyc.kbcfp.com> Cache-Post-Path: master.nyc.kbcfp.com!unknown@aphelion.nyc.kbcfp.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1070889942 29636 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:3227 Date: 2003-12-08T08:25:42-05:00 List-Id: Dmitry A. Kazakov wrote: > C++ does not distinguish class-wide and specific types. C++ has no concept of a classwide type as such, and certainly does not support having objects of classwide type, that much is true. > The same object is treated as a class-wide or specific > depending on the run-time call context. Objects declared as a certain type are always treated as that specific type. Pointers and references to classes are treated as potential pointers to some derived class. But I don't think that's what you mean. > class X > { > public : > virtual void Foo (); > virtual void Baz () { Foo (); } > ... > > Is the call to Foo from Baz dispatching? The answer is, well, > sometimes it will. > [*] "this" is a class-wide pointer when Baz was not directly or > indirectly called from a constructor/destructor. It is a specific > pointer otherwise. No, that is incorrect, showing the level-one misunderstanding of how this works. (Level-zero is to fail to realize that there's anything special about this case.) The call to Foo from Baz is always dispatching, regardless of whether Baz is called from a *tor or from somewhere else. It is the dispatch table (or whatever equivalent mechanism the compiler might use) which changes during *tor execution. The rule is that while a *tor is executing, the dynamic type of the object is that type. The "this" pointer is always "classwide", it's the dynamic type which is changing. As an example, the following prints ABB: #include struct A { virtual void f() { printf("A"); } void g() { f(); } A() { g(); } }; struct B : A { void f() { printf("B"); } B() { g(); } }; int main() { B b; b.g(); } > Arguably C++ is not strongly typed because no type could be addressed > to implicit "this" in Baz, and so to the actual type. The type of "this" in Baz is (always) pointer-to-X. > In Ada one can always statically determine whether a call is > dispatching. In C++ as well.