🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.windows.x
Article #38369

Re: C++ and callbacks

#38369
From: Glenn M. Poorman
Date: Tue, 03 May 1994 12:15
26 lines
2357 bytes
In article <pauld.767898877@sarge>, pauld@verdix.com (Paul Durbin) writes:
|> I attempt to use a member function as callback but all three arguments (to the
|> callback) are garbage. If I make it a friend then the arguments are correct,
|> but then I can't get to the class data, without reference thru an instance of
|> the class and I don't want the data to be static.
|> 
|> So, what is causing this problem? Could I possibly use the *this pointer as
|> the client_data to the callback, then cast to the appropriate class?

The problem is that the first argument of any non-static member function in
C++ is the "this" pointer.  So if you try to register a member function
as a callback with (i.e. Motif), it won't work because Motif doesn't know
that the function it is calling is a member function and it will not pass
the "this" pointer.

Unfortunately, the only way around this problem (as far as I know) is to either
use the "this" pointer as the client_data (as you mentioned above) or write your
own mechanism for registering member functions as callbacks.

-- 
=========================================================================
Glenn M. Poorman             Ford Motor Company
Rm 2228, Bldg #3             Phone: (313) 33-73316
20000 Rotunda Dr.            Fax  : (313) 39-08817
Dearborn, MI. 48121          Email: poorman@cadcam.pms.ford.com
=========================================================================
Technical Details
Message-ID: <2q5f97INNt6o@eccdb1.pms.ford.com>
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!hookup!yeshua.marcam.com!zip.eecs.umich.edu!newsxfer.itd.umich.edu!jobone!slee01.srl.ford.com!eccdb1.pms.ford.com!cc4032.pms.ford.com!poorman
References: <pauld.767898877@sarge>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,ad5a39011a2d3d26
X-Google-Attributes: gid109fba,public
X-Google-Thread: 103734,ad5a39011a2d3d26
X-Google-Attributes: gid103734,public
X-Google-Thread: 10ba33,ad5a39011a2d3d26
X-Google-Attributes: gid10ba33,public
X-Google-ArrivalTime: 1994-05-03 05:25:40 PST
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!hookup!yeshua.marcam.com!zip.eecs.umich.edu!newsxfer.itd.umich.edu!jobone!slee01.srl.ford.com!eccdb1.pms.ford.com!cc4032.pms.ford.com!poorman
From: poorman@cc4032.pms.ford.com (Glenn M. Poorman)
Newsgroups: comp.windows.x,comp.lang.c++,gnu.g++.help
Subject: Re: C++ and callbacks
Date: 3 May 1994 12:15:35 GMT
Organization: ECC at Ford Motor Company, Dearborn Michigan
Lines: 26
Distribution: world
Message-ID: <2q5f97INNt6o@eccdb1.pms.ford.com>
References: <pauld.767898877@sarge>
NNTP-Posting-Host: cc4032.pms.ford.com