1

Error Signal Handler function call error.

I have a method in a class there i am calling addTime(unsigned long milliSecs, BaseClass *bs, void *data) function.

//file BaseClass.h
class BaseClass {
public:
    virtual ~BaseClass(){ }

    virtual void OnTimedout(void* data)=0;
};

//file ClassBTxxx.h
#include "TimedOut.h"
class ClassBTxxx : public BaseClass
{
public :
    ClassBTxxx();
    void functionA();
    void OnTimedout(void* data);
    .........
    .........
    TimedOut* m_TimeOut;
};

//file ClassBTxxx.cpp
ClassBTxxx::functionA()
{
    m_TimeOut = new TimeOut();

    int timeoutId =m_TimeOut->addTime(18000, this, NULL);
}

ClassBTxxx::OnTimedout(void* data)
{
    printf("OnTimedout Signal handling function is called properly\n\n");
}

//file TimedOut.h
class TimedOut
public:
    TimedOut();
    int addTime(unsigned long milliSecs, BaseClass *ph, void *data);
    ~TimedOut(){}
protected:
    itimerval m_TimerValue;
};

//file TimedOut.cpp
int TimedOut::addTime(unsigned long milliSecs, BaseClass *ph, void *data) // iam passing the ClassBTxxx object to the *ph.
{
    printf("TimedOutHandler::addTimeout\n\n");
    m_TimerValue.it_value.tv_sec = 0;
    m_TimerValue.it_value.tv_usec = milliSecs;
    m_TimerValue.it_interval.tv_sec = 0;
    m_TimerValue.it_interval.tv_usec = milliSecs;

    int ret = setitimer(ITIMER_REAL,&m_TimerValue,0); //I am setting the timer for 3 second after 3 second expired my timer has to call OnTimedout() function.
    if(0 == ret)
    {
        printf("setitimer successful\n");
        signal(SIGALRM, ph->OnTimedout(data)); //Error: Invalide use of non-static memeber function
                                               //Error: Invalide conversion of void expression
    }
    else
    {
        printf("Set Timer Unsuccessful. %d\n", ret);
    }
    return 0;
}

The issue is I am setting the timer for 3 second after 3 second expired my timer has to call OnTimedout() function. The signal SIGALRM will deliver after 3 second and it has to call the OnTimedout(). I am getting the following error

Error: Invalide use of non-static memeber function
Error: Invalide conversion of void expression

Please help me to resolve this error. Thank you

Mohit Jain
  • 30,259
  • 8
  • 73
  • 100
  • Make your function static or use boost if you don't want static function. – pragnesh Mar 04 '15 at 06:18
  • Related: [Why callback functions needs to be static when declared in class](http://stackoverflow.com/questions/2400690/why-callback-functions-needs-to-be-static-when-declared-in-class) – Mohit Jain Mar 25 '15 at 05:40

0 Answers0