2017-03-10 120 views
0

我是C++的新手,並試圖理解一些代碼(NS2中的數據包調度)。 在某些時候,數據包經過下面的代碼:在C++中處理程序類的打印名稱

void 
    Scheduler::dispatch(Event* p, double t) 
    { 
      if ((t < clock_) && (p->uid_ != 0)) { 
        fprintf(stderr, "ns: scheduler going backwards in time from %f to %f.\n", clock_, t); 
        dumpq(); 
      } 
      if (p->uid_ != 0) { 
        clock_ = t; 
        p->uid_ = -p->uid_; // being dispatched 
        p->handler_->handle(p); // dispatch      
      } else { 
        fprintf(stderr, "Warning: discarding Event without an a valid id\n"); 
      } 
    } 

我的問題:有沒有一種簡單的方法,我發現在這裏的類handler_是什麼,我應該找handle(p)

回答

1

有沒有一種簡單的方法可以讓我在這裏找到handler_的類是什麼以及我應該在哪裏查找handle(p)?

p->handler_->handle(p);處設置斷點並進入該斷點。

或者,在gdb,做info symbol p->handler_->handle

或通過nullptr轉換爲handle希望它崩潰並轉儲核心或顯示堆棧跟蹤。

您還可以獲得對象的類mangled名稱如typeid(*p->handler_).name()