From 7498527412390235149
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,18c6d861cef54158
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2003-01-16 16:23:58 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!newsfeed.media.kyoto-u.ac.jp!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: allan_w@my-dejanews.com (Allan W)
Newsgroups: comp.std.c++
Subject: Re: automatic downcast support through function parameters
Date: Fri, 17 Jan 2003 00:23:54 +0000 (UTC)
Organization: http://groups.google.com/
Lines: 60
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <7f2735a5.0301160252.1526393b@posting.google.com>
References: <23478c42.0212310830.23dbc580@posting.google.com> <3E120608.6060608@tellabs.com> <23478c42.0301020923.79359e66@posting.google.com> <7f2735a5.0301071313.88d2480@posting.google.com> <23478c42.0301150659.1eefb5e0@posting.google.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: mail2news.demon.co.uk 1042763034 16299 10.0.0.1 (17 Jan 2003 00:23:54 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Fri, 17 Jan 2003 00:23:54 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.05)
	id 18ZKIa-0004Ek-00
	for mail2news@news.news.demon.net; Fri, 17 Jan 2003 00:23:53 +0000
X-Received: by mulga.cs.mu.OZ.AU
	id LAA18486; Fri, 17 Jan 2003 11:23:48 +1100 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ncar.ucar.edu
X-Newsgroups: comp.std.c++
X-NNTP-Posting-Date: 16 Jan 2003 10:52:03 GMT
X-Spam-Status: No, hits=-8.3 required=5.0
	tests=NOSPAM_INC,QUOTED_EMAIL_TEXT,REFERENCES,SPAM_PHRASE_05_08
	version=2.41
Xref: archiver1.google.com comp.std.c++:17161

danielgutson@hotmail.com (danielgutson@hotmail.com) wrote
> allan_w@my-dejanews.com (Allan W) wrote
> 
> Hello Alan:
Allan.

> First, I'm afraid that virtual functions can only be member functions,
> as far as there is a 'virtual table OF a class' (there are no 'global'
> virtual tables).
> (I strongly suggest to compile or test your code before posting).

I accidentally left the word "virtual" in the two free-standing
functions. I also used the wrong notation for calling "callg."
Try this version, which may do what you want without any language
changes:
> >     struct Base {
            ~Base();
> >         virtual void callg() { g(this); }
> >     };
> >     struct Der : public Base {
> >         virtual void callg() { g(this); }
> >     };
        void g(Base*) { std::cout << "g(Base*)"; }
        void g(Der*)  { std::cout << "g(Der *)"; }
> >     void callg(Base*b) { b->callg(); }
> >     int main() {
            Base *b = new Base;
            Base *d = new Der;
            //g(*d) would call the wrong version, but callg() figures it out:
            b->callg(); // Displays "g(Base*)"
            d->callg(); // Displays "g(Der *)"
            delete b;
            delete d;
> >     }

> Second, I'm not trying to do anything similar with virtual functions,
> just hold abstraction of the received parameter:
> a function receives an 'upcasted' parameter (contravariant), ignoring
> the original derived class, and simply recover it when used.
> As many people posted in this thread, RTTI is needed.
> They are also right about compiling units: the linker should solve
> this.

I'm trying to show that you can accomplish the same thing today, without
a language change ('upcasted parameter'). Once you've called the right
virtual function (in this case callg()), the virtual function "knows" the
right type and can call the correct free-standing function (g).

> Finally, the Visitor pattern does not apply to this situation.

I didn't think it would, directly. I just meant that you could
apply some of the same principals to call the correct code
depending on what data type was used.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



