Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!think.com!barmar From: barmar@think.com (Barry Margolin) Newsgroups: comp.lang.c++ Subject: Re: cast of a bound pointer: why ? Message-ID: <1991Jun12.192101.20607@Think.COM> Date: 12 Jun 91 19:21:01 GMT References: <1991Jun11.191016.9873@beaver.cs.washington.edu> <763@taumet.com> <1991Jun12.180414.16718@beaver.cs.washington.edu> Sender: news@Think.COM Reply-To: barmar@think.com Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 34 In article <1991Jun12.180414.16718@beaver.cs.washington.edu> pauld@stowe.cs.washington.edu (Paul Barton-Davis) writes: >This is the heart of the matter. C++ assumes that EVERY function >*requires* a "this" pointer. No, only member functions. >Any ideas on how one would do this if it were not possible (as it >currently is) to obtain the actual address of a member function ? >I have a few ideas myself, but would like to see some others if there >are any. Any problem (except efficiency, maybe) in computer science can be solved by adding enough levels of indirection. In this case, define a non-member function that takes the class object as a regular argument and simply invokes the member function, and pass the address of this non-member function. The non-member function would look something like this: int nonmember_fn (my_class object, int arg1, char *arg2) { return object.member_fn (arg1, arg2); } Actually, it might be a little easier in your case to use a my_class& first argument; otherwise, your assembly routine might have to invoke the class's memberwise initialization constructor during the calling sequence (this would actually be the case as well if any of the regular arguments were class objects). -- Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar