Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Function pointer not working too well...

Posted on 2009-07-07
5
Medium Priority
?
178 Views
Last Modified: 2012-05-07
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
Comment
Question by:Unimatrix_001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 2000 total points
ID: 24799759
Try calling it like:

void raiseEvent(){
                (listenerClassName->*listenerClassMember)();
        }
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 24799773
Ooops...
0
 
LVL 3

Author Closing Comment

by:Unimatrix_001
ID: 31600903
Thank you. :)
0
 
LVL 40

Expert Comment

by:evilrix
ID: 24801257
heh. I guess I went to be a little too early last night Uri :)
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 24803742
I went to bed waaay too late. ;)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question