Is it possible to use signal inside a C++ class?

前端 未结 5 1598
独厮守ぢ
独厮守ぢ 2020-12-02 13:19

I am doing something like this:

#include 

class myClass {
public: 
    void myFunction () 
    {
        signal(SIGIO,myHandler);
    }

            


        
5条回答
  •  伪装坚强ぢ
    2020-12-02 14:07

    To pass a pointer to a method, it must be a static method and you must specify the class name.

    Try this:

    class myClass {
      void myFunction () 
      {
        signal(SIGIO, myClass::myHandler);
      }
    
      static void myHandler (int signum)
      {
         // blabla
      }
    };
    

    And you should also read the link supplied by Baget, the paragraph 33.2 in the C++ FAQ.

提交回复
热议问题