🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.windows.x
Article #38368

Re: C++ and callbacks

#38368
From: Allan Engelhardt, CERN, ECP divi...
Date: Mon, 02 May 1994 19:19
38 lines
1886 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?
>
>thanks in advance for all the wonderful help.

Try a  static  member function and pass  this  in the client data.

	class foo
	{
		public :
		bar ();

		private :
		static void _bar ( Widget, XtPointer, XtPointer );
	}

	foo::_bar ( Widget, XtPointer, closure )
	{
		foo* fooP = (foo*) closure;
		fooP->bar ();
	}

	foo::mumble ( ... )
	{
		XtAddCallback ( ..., _bar, this );
		/* Or: ... (XtPointer) this */
	}


	--- Allan.

<ENGELHARDT@alonl.cern.ch>
Technical Details
Message-ID: <Cp6wCF.3E3@news.cern.ch>
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!hookup!yeshua.marcam.com!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!EU.net!CERN.ch!AL0W37.CERN.CH!ENGELHARDT
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-02 19:35:04 PST
Newsgroups: comp.windows.x,comp.lang.c++,gnu.g++.help
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!hookup!yeshua.marcam.com!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!EU.net!CERN.ch!AL0W37.CERN.CH!ENGELHARDT
From: engelhardt@AL0W37.CERN.CH (Allan Engelhardt, CERN, ECP division)
Subject: Re: C++ and callbacks
Message-ID: <Cp6wCF.3E3@news.cern.ch>
Sender: news@news.cern.ch (USENET News System)
Reply-To: engelhardt@AL0W37.CERN.CH
Organization: CERN
References: <pauld.767898877@sarge>
Date: Mon, 2 May 1994 19:19:26 GMT
Lines: 38