-1
我在ns2.35工作的另一個程序(C++)的變量,但我想從程序connector.cc 的#include「packet.h」訪問變量 的#include「connector.h」訪問在
int attacker = 0;
static class ConnectorClass : public TclClass {
到aodv.cc
#include <connector.h>
extern int attacker;
然後
if (malicious == 1000){
printf("\nDROPD\n");
drop(p, DROP_RTR_ROUTE_LOOP);
}
printf("\nAttacker: %d\n", &attacker);
例如我decla紅色變量int攻擊者= 0;在connector.cc中,我想在aodv.cc中訪問這個變量。 我該怎麼做?我無法使用上面的代碼。我正在使用C++。
預先感謝您:)
不知道爲什麼,但這個問題覺得我錯了。 –
你是否真的指同一個程序中的另一個*程序*或另一個*源文件*?如果是後者,則搜索並閱讀關於'extern'關鍵字以及如何在聲明中使用它。 –
「編制單位」我認爲是正確的術語。 –