Error using signal.h

Hi, everybody!

I have the problem when I compile my program and I really don't know what to do. First of all, I want to say that before writing here I was searching for the solutions, I have read the C++ FAQ and so on, but I still haven't solved it.

I always get the fallowing failure:

error: argument of type ‘void (WATCHDOG::)()’ does not match ‘void (*)(int)’

Here is the text of the program (before trying to edit it so as it can work)


void
WATCHDOG::cleanup() {
/* Show obtained data */
if (debug > 0) {
nei->ShowAllNeighbours(&neigs);
}
printf("\n\tFinishing watchdog...\t\tok!\n\n");
ShowStatistics();
close(sock);
nei->DeleteAllNeighbours(&neigs);
if (printPercentage) {
fclose(statistics);
}
exit(0);

}

void
WATCHDOG::setSignals() {
signal(SIGHUP, SIG_IGN);
signal(SIGINT, Cleanup);
signal(SIGTERM, Cleanup);
signal(SIGKILL, Cleanup);
signal(SIGQUIT, Cleanup);
}


This was the first variant of the code. After I got 4 errors in the last 4 lines I was trying to look for the solution. And accoeding to this: http://www.parashift.com/c++-faq-lite/pointers-to-members.html I thought I found it. Here is the modification:


void
WATCHDOG::cleanup() {
/* Show obtained data */
if (debug > 0) {
nei->ShowAllNeighbours(&neigs);
}
printf("\n\tFinishing watchdog...\t\tok!\n\n");
ShowStatistics();
close(sock);
nei->DeleteAllNeighbours(&neigs);
if (printPercentage) {
fclose(statistics);
}
exit(0);

}

void
WATCHDOG::Watchdog_memberFn_wrapper() {
object_which_will_handle_the_signal->cleanup();
}


void
WATCHDOG::setSignals() {
signal(SIGHUP, SIG_IGN);
signal(SIGINT, Watchdog_memberFn_wrapper);
signal(SIGTERM, Watchdog_memberFn_wrapper);
signal(SIGKILL, Watchdog_memberFn_wrapper);
signal(SIGQUIT, Watchdog_memberFn_wrapper);
}


But it still doesn't work. Please if there is anyone that can help me, help, cause I really don't know what to do.
What's more, I have this program written on C, and it works, but I know that signal.h works a little bit different in C++.

Thank you.


The problem is that your signal handling function doesn't have the same signature as what the signal function needs:

void (WATCHDOG::)()’ does not match ‘void (*)(int)

So, you can make your cleanup() function outside of your WATCHDOG class, or perhaps you can cast your function to be void( * )( int ).

Topic archived. No new replies allowed.