在下面的代码中
map<nsaddr_t, Rating*>::iterator it;
为以下行生成错误
(it->second)->updateRating(alpha, beta, TRUST_FADING, 1);
编译过程中出现“未定义引用”的错误。
语法是否正确或需要其他任何东西。
我没有在整个代码中找到 second 的声明。
void TrustManager::updateTrust(nsaddr_t address, double alpha, double beta)
{
map<nsaddr_t, Rating*>::iterator it;
it = trust_t.find(address);
if (it == trust_t.end())
{
trust_t[address] = initNewRating(alpha, beta, 1);
}
else
{
(it->second)->updateRating(alpha, beta, TRUST_FADING, 1);
}
}
bool TrustManager::isTrustworthy(nsaddr_t from)
{
map<nsaddr_t, Rating*>::iterator it;
it = trust_t.find(from);
if (it != trust_t.end())
{
double alpha = (it->second)->getAlpha();
double beta = (it->second)->getBeta();
double dev = alpha/(alpha+beta);
return (dev >= UNTRUST_TOLERANCE) ? false:true;
}
else
return true;
}
完整的错误是
In function `TrustManager::updateTrust(int, double, double)':
:(.text+0xde): undefined reference to `Rating::updateRating(double, double, double, double)'
In function `TrustManager::handleInactivityTimeout()':
(.text+0x241): undefined reference to `Rating::updateRating(double, double, double, double)'
In function `TrustManager::initNewRating(double, double, double)':
trustmanager.cc:(.text+0x306): undefined reference to `Rating::updateRating(double, double, double, double)'
In function `DSRAgent::DSRAgent()':
(.text+0x5b7): undefined reference to `makeRouteCache()'
In function `RouteCache::pre_noticeRouteUsed(Path const&, Path&, double, ID const&)':
(.text+0x54b): undefined reference to `cache_ignore_hints'
routecache.cc:(.text+0x620): undefined reference to `cache_use_overheard_routes'
dsr/routecache.o: In function `RouteCacheClass::create(int, char const* const*)':
(.text._ZN15RouteCacheClass6createEiPKPKc[RouteCacheClass::create(int, char const*
const*)]+0x7): undefined reference to `makeRouteCache()'
collect2: ld returned 1 exit status
评级定义如下:
class Rating
{
public:
Rating() { alpha = 1.0; beta = 1.0;}
Rating(double a, double b) { alpha = a; beta = b; last_t =
Scheduler::instance().clock();}
void updateRating(double a, double b, double fading, double weight);
inline double getAlpha() { return alpha; }
inline double getBeta() { return beta; }
inline Time getTime() { return last_t; }
private:
//the rating of misbehavior
double alpha;
//the rating of good behavior
double beta;
//last updated time
Time last_t;
};
class PackData {
public:
PackData();
PackData(Packet* packet, Time t);
Packet* packet;
Time t;
};