TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: BEN LIPPMEIER
from: WIM VELDHUIS
date: 1997-03-17 21:55:00
subject: Need help getting &Mouse::eventhandler 21:55:5903/17/97

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)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.