jewee
asked on
Cannot declare member function to have static linkage - -HELP!
I am trying to catch a signal and am having problems with the handler. I declared a static function to handle the signal, but I keep on getting this error:
"Cannot declare member function 'void SignalThread::messageHandl er(int) to have static linkage.
(This class inherits from QThread)
Here is the some of the code:
void SignalThread::run()
{
for (;;)
{
signalServerFlag = 0;
signal(SIGUSR1, messageHandler);
}
}
static void SignalThread::messageHandl er(int signum)
{
signalServerFlag = 1;
window->show();
return;
}
"Cannot declare member function 'void SignalThread::messageHandl
(This class inherits from QThread)
Here is the some of the code:
void SignalThread::run()
{
for (;;)
{
signalServerFlag = 0;
signal(SIGUSR1, messageHandler);
}
}
static void SignalThread::messageHandl
{
signalServerFlag = 1;
window->show();
return;
}
If the messageHandler function is not a member of the base class, the "static" keyword needs to be in the class declaration, and not in the definition:
class SignalThread : public QThread
{
...
static void messageHandler(int signum);
...
};
And then in the cpp file:
void SignalThread::messageHandl er(int signum)
{
}
class SignalThread : public QThread
{
...
static void messageHandler(int signum);
...
};
And then in the cpp file:
void SignalThread::messageHandl
{
}
And another hint:
You call window->show ();
But window is not a local variable. If it is a member of SignalThread it must be static as well be accessible from a static function.
You call window->show ();
But window is not a local variable. If it is a member of SignalThread it must be static as well be accessible from a static function.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or that ;-)
https://www.experts-exchange.com/questions/21137712/Problem-with-member-in-static-member-function.html
Replace 'MyThread' by 'SignalThread' and 'signalHandler' by 'messageHandler'
Regards, Alex
https://www.experts-exchange.com/questions/21137712/Problem-with-member-in-static-member-function.html
Replace 'MyThread' by 'SignalThread' and 'signalHandler' by 'messageHandler'
Regards, Alex
itsmeandnobodyelse,
FYI:
I always use the short version of the links, not because I want to save typeing, but because if you click on the short version, you still get the same EE look that you're already in.
Example:
Old-Look
http://oldlook.experts-exchange.com/questions/21137645/Cannot-declare-member-function-to-have-static-linkage-HELP.html
New-Look
https://www.experts-exchange.com/questions/21137645/Cannot-declare-member-function-to-have-static-linkage-HELP.html
Your-current-look
http:Q_21137645.html
Since I realy, realy, realy hate the new look, I post the short version, so as not to force the reader into a look they don't want.
FYI:
I always use the short version of the links, not because I want to save typeing, but because if you click on the short version, you still get the same EE look that you're already in.
Example:
Old-Look
http://oldlook.experts-exchange.com/questions/21137645/Cannot-declare-member-function-to-have-static-linkage-HELP.html
New-Look
https://www.experts-exchange.com/questions/21137645/Cannot-declare-member-function-to-have-static-linkage-HELP.html
Your-current-look
http:Q_21137645.html
Since I realy, realy, realy hate the new look, I post the short version, so as not to force the reader into a look they don't want.
@axter
it wasn't done purposely as i didn't know there is an old look.
how do i get a short link? Is there any accelerator or do i have to delete the path? And how to change to the old look?
Regards, Alex
it wasn't done purposely as i didn't know there is an old look.
how do i get a short link? Is there any accelerator or do i have to delete the path? And how to change to the old look?
Regards, Alex
>>it wasn't done purposely as i didn't know there is an old look.
I didn't think you did it intentional, that's why I posted it as an FYI :-)
>>how do i get a short link?
Just posted exactly as you see in the link I posted. (http:????????ID.html)
>>And how to change to the old look?
Just replace www to oldlook.
https://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus
to
http://oldlook.experts-exchange.com/Programming/Programming_Languages/Cplusplus
The one bad thing about the oldlook, is that when you get an email notification, the email notification has links to the new look.
Also, recently, it looks like the search engine has been disabled for the oldlook. I'm not sure if that's a temporary bug, or permanent.
I didn't think you did it intentional, that's why I posted it as an FYI :-)
>>how do i get a short link?
Just posted exactly as you see in the link I posted. (http:????????ID.html)
>>And how to change to the old look?
Just replace www to oldlook.
https://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus
to
http://oldlook.experts-exchange.com/Programming/Programming_Languages/Cplusplus
The one bad thing about the oldlook, is that when you get an email notification, the email notification has links to the new look.
Also, recently, it looks like the search engine has been disabled for the oldlook. I'm not sure if that's a temporary bug, or permanent.
@axter:
Thanks. I'll give it a try.
Thanks. I'll give it a try.
Check out the generic solution at http://www.codeproject.com/win32/callback_adapter.asp ("Use member functions for C-style callbacks and threads - a general solution"), this applies also for non-windows programs.