🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.windows.x
Article #38371

Re: C++ and callbacks

#38371
From: Kit Kauffmann
Date: Mon, 02 May 1994 15:52
25 lines
2016 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?

Not that one can tell from your post, but I'm assuming you mean Windows 
callbacks functions, as used by EnumChildWindows or something?

Of course normal member functions cannot be used for this purpose, having the 
hidden this pointer in the parameter list: only static member functions (or 
plain old functions) can be used as Windows callbacks.

To get to instance data, you can certainly pass 'this' and cast it; you could 
also assign 'this' to a static pointer to type <class>.

Cheers,

Kit Kauffmann   kitk@mudshark.sunquest.com (Internet)
                73363,447 (Compu$erve)
                (801) 277-5790
Technical Details
Message-ID: <kitk.632.000FDFA1@mudshark.sunquest.com>
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!hookup!usc!elroy.jpl.nasa.gov!ncar!noao!CS.Arizona.EDU!venus.sunquest.com!mudshark.sunquest.com!kitk
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 10:48:01 PST
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!hookup!usc!elroy.jpl.nasa.gov!ncar!noao!CS.Arizona.EDU!venus.sunquest.com!mudshark.sunquest.com!kitk
From: kitk@mudshark.sunquest.com (Kit Kauffmann)
Newsgroups: comp.windows.x,comp.lang.c++,gnu.g++.help
Subject: Re: C++ and callbacks
Date: Mon, 2 May 1994 15:52:18
Organization: Sunquest
Lines: 25
Message-ID: <kitk.632.000FDFA1@mudshark.sunquest.com>
References: <pauld.767898877@sarge>
NNTP-Posting-Host: kkauffma.sunquest.com
X-Newsreader: Trumpet for Windows [Version 1.0 Rev A]