Ptrs to functions (gcc vs. egcs)

Mike tinnes@kitten.ndscs.NoDak.edu
Wed Mar 31 23:46:00 GMT 1999


The following code compiles and executes fine under RH5.0 gcc, but failes
with egcs-2.90.29 980515 (egcs-1.0.3 release) running under RH5.2. The
error message is:

  test.cpp: In method `void Test::bar()':
  test.cpp:26: must use .* or ->* to call pointer-to-member function in
  `ptr (...)'

Here's the code:

#include <iostream.h>

class Test
{
  public:
	typedef void (Test::*sPtr)( void );    	

	Test() : fooPtr(&foo) {};
	~Test() {};

	sPtr fooPtr;

	void foo();
	void bar();
};

void Test::foo()
{
	cout << "foo called" << endl;
}

void Test::bar()
{
	sPtr ptr = fooPtr;

	ptr();
}

int main()
{
	Test test;

	test.bar();
}

Is there a way to make this work w/o static functions?

thanks, Mike




More information about the Gcc mailing list