Pointers to methods

nazriel spam at dzfl.pl
Sun Mar 3 19:21:32 PST 2013


Greetings.

While playing with D code (http://dpaste.dzfl.pl/c6d9e5bd) I 
noticed that I have no idea how to write equivalent to this C++ 
code:

http://dpaste.dzfl.pl/ae182695 *[1]

Could somebody point me out how to achieve same thing? Maybe I am 
missing something obvious? Thanks!

*[1] - code for lazy people :
#include <cstdio>

class A
{
	int x;

public:
	A(int y) : x(y){}

	void foo()
	{
		printf("::foo(), x: %d\n", x);
	}
};

class B : public A
{
public:
	B(int y) : A(y)
	{}		
};

int main(void)
{
	void (A::*fp)() = &A::foo;

	A a(3);
	B b(4);

	(a.*fp)();
	(b.*fp)();

	return 0;
}


More information about the Digitalmars-d-learn mailing list