2014-02-10 50 views
0

我在NS2中實現一個定時器時遇到了一個問題。我想實現一個計時器,它在到期時打印「過期」。代碼如下:NS2中的定時器導致分段錯誤

fap.h:

class Fap; 
class HelloTimer : public TimerHandler 
{ 
    public: 
    HelloTimer(Fap* fapAgent) : TimerHandler(){agent = fapAgent;}  
    protected: 
    Fap* agent; 
    inline virtual void expire(Event* e);   

}; 

class Fap : public Agent 
{ 
public: 
Fap(void); 
int filter[ADDRESS_SPACE]; 
int address; 
int netId; 
int requestedIp; 
bool configured; 
nsaddr_t requestor; 
nsaddr_t initiator; 
HelloTimer helloTimer; 
TcpAgent* tcp; 
NsObject* ll; 
void recv(Packet* p, Handler*); 
void sendHello(void); 
int command(int, const char* const*); 
}; 

fap.cc

void HelloTimer:: expire(Event* event) 
{ 
//agent->sendHello(); 
printf("expired\n");  
} 
int Fap::command(int argc, const char* const* argv) 
{ 
Tcl& tcl = Tcl::instance(); 
if(argc == 2) 
{ 
    if(strcmp(argv[1], "hello") == 0) 
    { 
     helloTimer.resched(30); //problem occurs here 
        helloTimer.status(); //no problem with this 
        return (TCL_OK); 
    } 
} 
else if(argc == 3) 
{ 

    if(strcmp(argv[1], "set-ll") == 0) 
    { 
     NsObject* temp; 
     temp = (NsObject*)(TclObject::lookup(argv[2])); 
     ll = temp; 
     return (TCL_OK); 
    } 


} 
else 
{ 
    printf("invalid number of args"); 

} 
Agent::command(argc,argv); 
return(TCL_OK); 

} 

的代碼中,只有相關部分已經added.Whenever我嘗試重新安排使用計時器resched (),發生分段錯誤。我錯過了什麼嗎?

回答

0

這是由於類名衝突的結果。只需將您的計時器類名稱的前綴。