D
Dudebot
Hi Gurus, I'm porting some C code into a C++ environment. I have
working signal code in C:
#includes for signal...
static void exit_gracefully()
{
*control = STOP|TWSIEN; // send stop signal
exit( 0 );
}
int main( int argc, char **argv )
{
....
signal( SIGTERM, exit_gracefully );
However, when I try to port it into a class, e.g.
class ADC {
public:
....
void sample(); // sample ADC
private:
volatile unsigned int *control;
void exit_gracefully();
};
void ADC::exit_gracefully()
{
*control = STOP|TWSIEN; // send stop signal
exit( 0 );
}
void ADC::sample()
{
....
signal( SIGTERM, exit_gracefully );
I get these compilation errors:
error: argument of type `void (ADC:()' does not match `void
(*)(int)'
I can't pull exit_gracefully() out of the class, as it needs to access
the private member control.
I tried casting the function in the signal call
signal( SIGTERM, void (*)(int) exit_gracefully );
But I'm getting
error: parse error before `)' token
I tried all sorts of typedef conconctions a la
http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33.5,
but can't get anything to help.
Any ideas?
Many TIA,
Craig
working signal code in C:
#includes for signal...
static void exit_gracefully()
{
*control = STOP|TWSIEN; // send stop signal
exit( 0 );
}
int main( int argc, char **argv )
{
....
signal( SIGTERM, exit_gracefully );
However, when I try to port it into a class, e.g.
class ADC {
public:
....
void sample(); // sample ADC
private:
volatile unsigned int *control;
void exit_gracefully();
};
void ADC::exit_gracefully()
{
*control = STOP|TWSIEN; // send stop signal
exit( 0 );
}
void ADC::sample()
{
....
signal( SIGTERM, exit_gracefully );
I get these compilation errors:
error: argument of type `void (ADC:()' does not match `void
(*)(int)'
I can't pull exit_gracefully() out of the class, as it needs to access
the private member control.
I tried casting the function in the signal call
signal( SIGTERM, void (*)(int) exit_gracefully );
But I'm getting
error: parse error before `)' token
I tried all sorts of typedef conconctions a la
http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33.5,
but can't get anything to help.
Any ideas?
Many TIA,
Craig