Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

How to pass address of member function as parameter

$
0
0

Help please,

I have created this bit of code to illustrate my problem. I wish to pass the address of a member function as a parameter in the constructor of another class. In my example, I don't want X to have any knowledge of A or B. Is there anyway to pass the address without getting compile errors. The code is unmanaged (no clr).

typedef void(*DISP)(char*);

class X
{
public:
	DISP disp;

	X(DISP pdisp) {
		disp = pdisp;
	}

	X() {}
};

class A {
public:
	X *ax;

	A() {
		ax = new X(&display);
	};

	void display(char * msg){ }
};

class B {
public:
	X *bx;

	B() {
		bx = new X(&display);
	};

	void display(char * msg){ }
};

int main() {
	A a;
	B b;
};


Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>