-3

这是头文件名 monitor.h

class DSRAgent;
class Detector;
class ReputationSystem;

class Monitor {
public:
    Monitor();
    Monitor(DSRAgent* agent);
    void handleTap(const Packet* packet);
    void handlePublishInfo(nsaddr_t src, double identification, int count,rating* ratings);
    void handlePacketSent(Packet* packet);
    void publishInfo(map<nsaddr_t, rating*> ratings);
    void setNetID(nsaddr_t netid); 
    nsaddr_t getNetID();
    friend class PackTableTimer;
    void setReputationSystem(ReputationSystem* rep_system);
    bool isPACK(int uid);
    void Terminate();

    PackTableTimer* pack_table_timer;

private:
    void packTableCheck();
    map<nsaddr_t, double> published_ids;
    PackTable pack_t;
    DSRAgent* dsragent;
    Detector* detector;
    ReputationSystem* reputation_system;
    nsaddr_t net_id; 
};
class PackTableTimer : public TimerHandler {
public:
PackTableTimer(Monitor *a) : TimerHandler() { a_ = a;}
void expire(Event *e);
protected:
Monitor *a_;
};

另一个文件是 monitor.cc

void PackTableTimer::expire(Event *e)
{
    a_->packTableCheck();
    resched(PACK_TIMEOUT + PACK_TIMEOUT * Random::uniform(1.0));
}

DSRAgent* dsragent;

Monitor::Monitor(DSRAgent* agent)
{ 
    this->dsragent = agent;
    this->detector = new Detector(this);
    pack_table_timer = new PackTableTimer(this);
    pack_table_timer->sched(PACK_TIMEOUT + PACK_TIMEOUT * Random::uniform(1.0));
}

void Monitor::handleTap(const Packet* packet)
{
    Behavior behavior;
    hdr_sr *srh = hdr_sr::access(packet);
    hdr_ip *iph = hdr_ip::access(packet);
    hdr_cmn *cmh = hdr_cmn::access(packet);
    ID cur_hop(srh->addrs()[srh->cur_addr()-1]);
    nsaddr_t cur_addr = cur_hop.getNSAddr_t();
    int uid = cmh->uid();
    map<int, PackData*>::iterator it;
    it = pack_t.find(uid);

我收到以下错误:

**monitor.h:错误:“PackTableTimer”未命名类型

monitor.cc:在构造函数“Monitor::Monitor(DSRAgent*)”中

monitor.cc:错误:“类监视器”没有名为“PackTableTimer”的成员

monitor.cc:错误:“pack_table_timer”未在此范围内声明**
4

2 回答 2

1

您错过了 PackTableTimer 类的声明。

于 2013-04-13T16:06:41.590 回答
1

您需要先进行前向声明PackTableTimer,然后才能使用它monitor.h

将此与您的其他前向声明放在一起。

class PackTableTimer;
于 2013-04-13T16:19:13.670 回答