这是头文件名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: error: ‘PackTableTimer’ does not name a type monitor.cc: In constructor ‘Monitor::Monitor(DSRAgent*)’ monitor.cc: error: ‘class Monitor’ has no member named ‘PackTableTimer’ monitor.cc: error: ‘pack_table_timer’ was not declared in this scope**
答案 0 :(得分:1)
你错过了PackTableTimer类的声明。
答案 1 :(得分:1)
您必须先向前声明PackTableTimer
,然后才能在monitor.h
将此与您的其他前向声明一起使用。
class PackTableTimer;