🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++
Article #467

Re: Pointers to member functions

#467
From: Jonathan D. Becher
Date: Wed, 07 Jun 1989 23:06
37 lines
1370 bytes
In article <29523@ucbvax.BERKELEY.EDU> Marc Singer writes:
>How does one call a member function using a pointer to that function?
> ...
>Ahem.  It did not work.  
>
>Marc Singer

Early versions of C++ did not support pointer to member functions.
If you look closely at the very small print on the bottom of page
154 in Stroustrup's book, he describes how pointer to member functions
can be declared and used. Basically, it looks like this:

	class classname
	{
	    char memberVar;
	
	public:
	    void memberFunc (int param) { memberVar = param; }
	};

	typedef void (classname::*ptrToMemFunc)(int);

	main()
	{
	    ptrToMemFunc pf1 = &classname::memberFunc;
	    classname instance;

	    // call memberFunc with parameter 2
	    (instance.*pf1)(2);
	}

This works in G++ 1.25.0 (and newer versions, I assume).

Jon Becher
argosy!becher@decwrl.dec.com

"Read the fine print carelessly; you never know what you will find"
Technical Details
Message-ID: <116@armada.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!shelby!decwrl!armada!becher
References: <29523@ucbvax.BERKELEY.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!shelby!decwrl!armada!becher
From: becher@armada.UUCP (Jonathan D. Becher)
Newsgroups: gnu.g++
Subject: Re: Pointers to member functions
Message-ID: <116@armada.UUCP>
Date: 7 Jun 89 23:06:39 GMT
References: <29523@ucbvax.BERKELEY.EDU>
Reply-To: becher@zaphod.UUCP (Jonathan D. Becher)
Organization: we don' need no steekin' organeezation
Lines: 37