次のコードでは
map<nsaddr_t, Rating*>::iterator it;
次の行のエラーを生成します
(it->second)->updateRating(alpha, beta, TRUST_FADING, 1);
コンパイル中の「未定義の参照」のエラー。
構文は正しいですか、それとも他の何かが必要ですか。
コード全体で秒の宣言が見つかりませんでした。
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;
};