Using C signal handler in my class

B

Ben

The signal() is the one in signal.h (csignal), in my class I defined a
SIGALRM handler and then in my constructor I wrote signal(SIGALRM,
myHandler), but the compiler gave me the error:
error: argument of type 'void (myClass::)(int)' does not match 'void
(*)(int)'
Where have I done wrong?
 
V

Victor Bazarov

Ben said:
The signal() is the one in signal.h (csignal), in my class I defined a
SIGALRM handler and then in my constructor I wrote signal(SIGALRM,
myHandler), but the compiler gave me the error:
error: argument of type 'void (myClass::)(int)' does not match 'void
(*)(int)'
Where have I done wrong?

You've not read the FAQ before posting. Search for "callback" in
the FAQ, it should hopefully clear some stuff up.

V
 
B

Ben

You've not read the FAQ before posting. Search for "callback" in
the FAQ, it should hopefully clear some stuff up.

V
Thanks, V. Just wondering is there a direct link to the FAQ? I found
it using search.
 
G

Guest

The signal() is the one in signal.h (csignal), in my class I defined a
SIGALRM handler and then in my constructor I wrote signal(SIGALRM,
myHandler), but the compiler gave me the error:
error: argument of type 'void (myClass::)(int)' does not match 'void
(*)(int)'
Where have I done wrong?

signal() expects a function pointer and not a member function pointer.
You can not have a member function as a callback for C functions, only
plain functions will work.
 
I

Ian Collins

Erik said:
signal() expects a function pointer and not a member function pointer.
You can not have a member function as a callback for C functions, only
plain functions will work.
Plain functions with extern "C" linkage.
 
I

Ian Collins

*Please* don't quote signatures.
Speaking of extern linkage, do I need to apply this to those c headers
like "unistd.h", "fcntl.h"?
No, they will have their own C++ wrappers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top