Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Problem setting signal handler

Reply
Thread Tools

Problem setting signal handler

 
 
pradeep
Guest
Posts: n/a
 
      04-26-2008
Hello again friends:

I'm now trying to get a signal handler to work. I have made the example
code below to check I can make it work, but there is a compiler error,

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

Can anyone help?

Thanks.



#include <iostream>
#include <signal.h>

class MyApp {
public:
MyApp(void) { signal(SIGINT, Handler); }
~MyApp(void) { signal(SIGINT, SIG_DFL); }
void Handler(int) { std::cerr << "test\n"; }
};

void main()
{
MyApp x;
sleep(10);
return 0;
}
 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      04-26-2008
pradeep wrote:
> Hello again friends:
>
> I'm now trying to get a signal handler to work. I have made the example
> code below to check I can make it work, but there is a compiler error,
>
> argument of type ‘void (MyApp:(int)’ does not match ‘void (*)(int)’

^^^^^^^^

How many times do you need to be told that the language of
<news:comp.lang.c> is C. Why do you keep posting some other language
here?
 
Reply With Quote
 
 
 
 
Antoninus Twink
Guest
Posts: n/a
 
      04-26-2008
On 26 Apr 2008 at 21:41, pradeep wrote:
> I'm now trying to get a signal handler to work. I have made the example
> code below to check I can make it work, but there is a compiler error,

[snip]
> class MyApp {
> public:
> MyApp(void) { signal(SIGINT, Handler); }
> ~MyApp(void) { signal(SIGINT, SIG_DFL); }
> void Handler(int) { std::cerr << "test\n"; }
> };


The problem is that non-static member functions take an extra hidden
parameter (namely the "this" pointer to the current instance of the
class), so you can't use a pointer to a non-static member function as a
general pointer to a function.

The easiest solution for you will be to make the Handler function
static.

 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      04-27-2008
pradeep wrote:

> Hello again friends:
>
> I'm now trying to get a signal handler to work. I have made the
> example code below to check I can make it work, but there is a
> compiler error,
>
> argument of type ?void (MyApp:(int)? does not match ?void (*)(int)?
>
> Can anyone help?
> Thanks.
>
> #include <iostream>
> #include <signal.h>


<snip>

Please post to <news:comp.lang.c++>. It should be carried on virtually
all Usenet servers including the one you seem to be using. A program
using C that is a proper subset of C++ is topical in c.l.c++, but C++
is not topical here.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How does a handler render the request to another handler in the MVC of SPRING 2.0.1 framework? rayzyang@gmail.com Java 0 05-30-2007 11:28 AM
Event Handler that creates adds another event handler kaczmar2@gmail.com ASP .Net 1 02-22-2007 07:37 AM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
Re: JNI calls from inside UNIX signal handler Joseph Millar Java 5 07-10-2003 04:34 PM
Re: JNI calls from inside UNIX signal handler Marc Rochkind Java 0 07-09-2003 03:44 PM



Advertisments