Thanks for the constructive reply Zero, I'd been expecting something like "whichever you like"!
Anyone else?
Derek
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2003-01-22
The problem with static function sis that they cannot access non-static members, which may be a problem. In situations where it is, I have used a static function that takes an instance pointer as a parameter.
e.g.
static void myClass::callback( myClass* instance ) ;
In callback(), member functions and data may be called through the instance parameter.
If you base myClass on a generic base class where callback() is a virtual function. The class registering the callback would therefore only need to know about the base class making the mechanism generic.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
To clarify, the callback function that I am referring to in this instance is a windows procedure. Initially, a single main procedure, afterwards a procedure for multiple child windows.
Derek
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Looking on the 'net, there seem to be two solutions on the problem of callback and classes:
making the function static
using a global function to pass the parameters on to a class member function
Does anyone have any opinions on which to use?
Thanks in advance
Derek
I would make the member function static... less sloppy more portable in my opinion...
Zero Valintine
Thanks for the constructive reply Zero, I'd been expecting something like "whichever you like"!
Anyone else?
Derek
The problem with static function sis that they cannot access non-static members, which may be a problem. In situations where it is, I have used a static function that takes an instance pointer as a parameter.
e.g.
static void myClass::callback( myClass* instance ) ;
In callback(), member functions and data may be called through the instance parameter.
If you base myClass on a generic base class where callback() is a virtual function. The class registering the callback would therefore only need to know about the base class making the mechanism generic.
To clarify, the callback function that I am referring to in this instance is a windows procedure. Initially, a single main procedure, afterwards a procedure for multiple child windows.
Derek
Update:
I now have it working using a static member function for the WndProc, at least as a single window.
No doubt, more fun ahead as try to make it MDI and introduce multiple child window!
Derek