• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

Function pointer not working too well...

Hi,

Please see the code below - no message box is showing despite me asking the computer very nicely... :(

Thanks,
Uni
template<typename TListenerClassName>
class CEventRaiser{
public:
	typedef void (TListenerClassName::*ListenerClassMember)();
	void initialiseEventRaiser(TListenerClassName *aListenerClassName, ListenerClassMember aListenerClassMember){
		listenerClassName=aListenerClassName;
		listenerClassMember=aListenerClassMember;
	}
	void raiseEvent(){
		listenerClassName->*listenerClassMember;
	}
private:
	TListenerClassName *listenerClassName;
	ListenerClassMember listenerClassMember;
};
 
 
class CSample{
public:
	void init(){
		eventRaiser.initialiseEventRaiser(this, &CSample::listener);
		eventRaiser.raiseEvent();
	}
	void listener(){
		MessageBox(0, L"H", L"", 0);
	}
	CEventRaiser<CSample> eventRaiser;
};
 
 
int main(){
	CSample sample;
	sample.init();
	...
}

Open in new window

0
Unimatrix_001
Asked:
Unimatrix_001
  • 3
1 Solution
 
mrjoltcolaCommented:
Try calling it like:

void raiseEvent(){
                (listenerClassName->*listenerClassMember)();
        }
0
 
Unimatrix_001Author Commented:
Ooops...
0
 
Unimatrix_001Author Commented:
Thank you. :)
0
 
evilrixSenior Software Engineer (Avast)Commented:
heh. I guess I went to be a little too early last night Uri :)
0
 
Unimatrix_001Author Commented:
I went to bed waaay too late. ;)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now