Ben Lippmeier wrote in a message to All:
BL> for a current project, i have the desire to write an oop
BL> mouse handler..
...
BL> after much fooling around, ive managed to determine that
BL> a void Mouse::eventhandler(void);
BL> is of type void(Mouse::*)(). and not void (*)(void) like
BL> one would have expected (or at least, as i expected).
Yep, this is the result of the hidden this pointer.
If you make your methods static, they will satisfy the function signature,
but you will not directly be allowed access to the class attributes. Using a
singleton pattern (which makes sure there is only one instance) you can use
the single instance by using a static member like outlined below:
// Header file.
class Mouse {
private:
static Mouse* m_pInstance;
Mouse() {}; // private so only Mouse can create instances
~Mouse() {}; // dtor as well
public:
static Mouse* Instance();
static void eventhandler(void);
};
// Implementation file
static Mouse* Mouse::m_pInstance = 0;
Mouse* Mouse::Instance()
{
if( m_pInstance == 0 ) {
m_pInstance = new Mouse;
}
return m_pInstance;
}
void Mouse::eventhandler()
{
// your code, you can access the global instance
// with the Instance() method.
}
mvg/wr
--- timEd/2 1.01.g3+
---------------
* Origin: LightHouse BBS ==> I am a H.U.G.O. Member ! (2:285/324.3)
|