Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I pass a ptr to member fn to a signal handler,X event callback,etc?

0
Posted

How do I pass a ptr to member fn to a signal handler,X event callback,etc?

0

Don’t. Because a member function is meaningless without an object to invoke it on, you can’t do this directly (if The X Windows System was rewritten in C++, it would probably pass references to OBJECTS around, not just pointers to fns; naturally the objects would embody the required function and probably a whole lot more). As a patch for existing software, use a top-level (non-member) function as a wrapper which takes an object obtained through some other technique (held in a global, perhaps). The top-level function would apply the desired member function against the global object. E.g., suppose you want to call Fred::memfn() on interrupt: class Fred { public: void memfn(); static void staticmemfn(); //a static member fn can handle it //… }; //wrapper fn remembers the object on which to invoke memfn in a global: Fred* object_which_will_handle_signal; void Fred_memfn_wrapper() { object_which_will_handle_signal->memfn(); } main() { /* signal(SIGINT, Fred::memfn); */ //Can NOT do this s

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123