Click here to Skip to main content
15,920,801 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Function Pointer Pin
Stuart Dootson2-Mar-09 8:17
professionalStuart Dootson2-Mar-09 8:17 
QuestionRe: Function Pointer Pin
CPallini2-Mar-09 10:17
mveCPallini2-Mar-09 10:17 
GeneralRe: Function Pointer Pin
Richard Andrew x642-Mar-09 9:38
professionalRichard Andrew x642-Mar-09 9:38 
GeneralRe: Function Pointer [modified] Pin
Stuart Dootson2-Mar-09 10:02
professionalStuart Dootson2-Mar-09 10:02 
GeneralRe: Function Pointer Pin
Rajesh R Subramanian2-Mar-09 19:59
professionalRajesh R Subramanian2-Mar-09 19:59 
AnswerRe: Function Pointer Pin
Perisic, Aleksandar2-Mar-09 8:45
Perisic, Aleksandar2-Mar-09 8:45 
GeneralRe: Function Pointer Pin
Perisic, Aleksandar2-Mar-09 9:08
Perisic, Aleksandar2-Mar-09 9:08 
AnswerRe: Function Pointer [modified] Pin
Perisic, Aleksandar2-Mar-09 11:48
Perisic, Aleksandar2-Mar-09 11:48 
If you are ready to make a slight design change this is what you can do and to get something fairly useful
class T
{
public:
	virtual void run() = 0; // this does not have to be abstract if you don't like, but it saves some bits
	virtual void run1() = 0; // another possible event 
};

class A : public T
{
	public:	
		void run(){ // A version
		};

		void run1(){ // A version
		};
};

class F : public T
{
	public:	
		void run(){ // F version
		};

		void run1(){ // F version
		};
};

class R{
	public:	

	typedef void (T::*Method)(); // general abstract method used, it can point to any method without parameters
	Method onClick;	

	void Do(T* t) // abstract type used
	{		
		(t->*onClick)();	
	}
};

int _tmain(int argc, _TCHAR* argv[])
{
	A a;	// create object A
	F f;	// create object F

	R r;	
	r.onClick = &T::run; // set one general event

	// now different type passed leads to different call
	r.Do(&a); // A::run called
	r.Do(&f); // F::run called

	r.onClick = &T::run1; // set another general event

	// again different type passed leads to different call
	r.Do(&a); // A::run1 called
	r.Do(&f); // F::run1 called

	...


modified on Monday, March 2, 2009 5:57 PM

Question[Message Deleted] Pin
Davitor2-Mar-09 5:58
Davitor2-Mar-09 5:58 
AnswerRe: File handaling problem Pin
Richard Andrew x642-Mar-09 6:12
professionalRichard Andrew x642-Mar-09 6:12 
GeneralRe: File handaling problem Pin
Ric Ashton2-Mar-09 6:31
Ric Ashton2-Mar-09 6:31 
GeneralRe: File handaling problem Pin
Ric Ashton2-Mar-09 6:33
Ric Ashton2-Mar-09 6:33 
GeneralRe: File handaling problem Pin
Davitor2-Mar-09 6:45
Davitor2-Mar-09 6:45 
GeneralRe: File handaling problem Pin
Davitor2-Mar-09 6:42
Davitor2-Mar-09 6:42 
GeneralRe: File handaling problem Pin
Eytukan2-Mar-09 6:56
Eytukan2-Mar-09 6:56 
GeneralRe: File handaling problem Pin
Ric Ashton2-Mar-09 6:59
Ric Ashton2-Mar-09 6:59 
GeneralRe: File handaling problem Pin
Richard Andrew x642-Mar-09 7:44
professionalRichard Andrew x642-Mar-09 7:44 
AnswerRe: File handaling problem Pin
Maximilien2-Mar-09 6:53
Maximilien2-Mar-09 6:53 
GeneralRe: File handaling problem Pin
Davitor2-Mar-09 7:05
Davitor2-Mar-09 7:05 
GeneralRe: File handaling problem Pin
Maximilien2-Mar-09 7:16
Maximilien2-Mar-09 7:16 
AnswerRe: File handaling problem Pin
David Crow2-Mar-09 9:01
David Crow2-Mar-09 9:01 
QuestionConstructor / Destructor Question Pin
Richard Andrew x642-Mar-09 5:15
professionalRichard Andrew x642-Mar-09 5:15 
AnswerRe: Constructor / Destructor Question Pin
«_Superman_»2-Mar-09 5:31
professional«_Superman_»2-Mar-09 5:31 
GeneralRe: Constructor / Destructor Question Pin
Richard Andrew x642-Mar-09 6:10
professionalRichard Andrew x642-Mar-09 6:10 
GeneralRe: Constructor / Destructor Question Pin
Eytukan2-Mar-09 6:42
Eytukan2-Mar-09 6:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.