I am writing a class that works with port RS485 traffic. When opening the port, I indicate the function called when there is some data in the input buffer of the port:
struct sigaction saio; /* definition of signal action */ fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK); /* open the device to be non-blocking (read will return immediatly) */ if (fd <0) { perror(device);} sigemptyset(&saio.sa_mask); /* install the signal handler before making the device asynchronous */ saio.sa_handler = signal_handler_IO; If the function - the handler is described as a learning function:
void signal_handler_IO (int status){ if (read(fd,&buf,1)){ std::cout << "I'm recieve byte\t" << std::hex << buf[0] << std::dec << std::endl; } } That is no problem. But if I make this function a member of a class, then compile errors occur.
error: cannot convert 'Rs485::signal_handler_IO' from type 'void (Rs485::)(int)' to type '__sighandler_t {aka void (*)(int)}' I am not very strong in C ++ and do not understand what the compiler wants from me. Tell me please, how can I make a handler function a member of the class?
static? (the first thing that comes to mind when looking at a mistake) - Harry