🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Marc Singer Wed, 07 Jun 1989 17:36
Pointers to member functions
#464
Author: Marc Singer
Date: Wed, 07 Jun 1989 17:36
16 lines
1157 bytes
How does one call a member function using a pointer to that function.
I understand that some may feel it is a breech of good practice
since the language already has many features to eliminate the
need for pointers to functions; still the problem remains.

When I called a member functions using a pointer to that function,
the code which normally pushes the $this pointer did not exist.
Hence, the receiving prologue popped the first parameter as the
$this pointer.  Ahem.  It did not work.  I want to use a member function
because I want the function to be an implicit intimate to the private
parts of the class.  Simulating the $this pointer would be acceptable.

Marc Singer
        "When fullness is taken from fullness,
         fullness still remains."
                        Invocation of the Isha Upanishad
Re: Pointers to member functions
#467
Author: 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"
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads