I am linking issues only in specific functions only. I have a base class Node(Node.h, Node.cpp) inherited by classes ActorNode(ActorNode.cpp) and SensorNode(SensorNode.cpp) and the main() is in seperate file Program.cpp.
This is the issue:
swar@swar-Inspiron-5520:~/swar/WSNProject/src$ g++ -std=c++11 -c Node.h Node.cpp ActorNode.cpp ChildNode.h SensorNode.cpp Program.cpp
swar@swar-Inspiron-5520:~/swar/WSNProject/src$ g++ Node.o ActorNode.o SensorNode.o Program.o
Program.o: In function `main':
Program.cpp:(.text+0x179): undefined reference to `std::vector<SensorNode, std::allocator<SensorNode> > Node::GetNodesInRange<SensorNode>(std::vector<SensorNode, std::allocator<SensorNode> >, double)'
Program.cpp:(.text+0x269): undefined reference to `void Node::Broadcast<SensorNode>(std::vector<SensorNode, std::allocator<SensorNode> >, Message, double)'
Program.cpp:(.text+0x447): undefined reference to `void Node::SendMsg<ActorNode>(Message, ActorNode)'
collect2: error: ld returned 1 exit status
swar@swar-Inspiron-5520:~/swar/WSNProject/src$ ^C
following are the code portions:
//Program.cpp
#include "ChildNode.h"
#include <typeinfo>
template <class T>
vector<T> InitNodeArray(int count);
template <class T>
void PrintNodeArray(vector<T> NodeArray);
//Length and breadth of area
int areaX, areaY;
int main()
{
do{
cout << "Enter the length and breadth of area under supervision" << endl << "X: ";
cin >> areaX;
cout << "Y: ";
cin >> areaY;
} while (typeid(areaX) != typeid(int) || typeid(areaY) != typeid(int));
vector<ActorNode> actorNodeArray = InitNodeArray<ActorNode>(ACTOR_NODE_COUNT);
vector<SensorNode> sensorNodeArray = InitNodeArray<SensorNode>(SENSOR_NODE_COUNT);
//only 1 actor node
vector<ActorNode>::iterator aIter;
vector<SensorNode>::iterator sIter;
//for each actor node
for(aIter = actorNodeArray.begin(); aIter!= actorNodeArray.end(); aIter++)
{
//get all in range sensor nodes
for (int iteration = 0; iteration < 3; iteration++)
{
aIter->SetIterRadius(iteration);
vector<SensorNode> inRangeSNode = aIter->GetNodesInRange<SensorNode>(sensorNodeArray, ACTOR_RANGE);
vector<SensorNode> RedSensorNodeArray;
for (sIter = inRangeSNode.begin(); sIter != inRangeSNode.end(); sIter++)
{
//hi message - to know who all are in range
sIter->Broadcast<SensorNode>(inRangeSNode, Message({ "", sIter->id, -1, TYPE0, true }), SENSOR_NODE_RANGE);
//set if is redundant
sIter->isRedundant = sIter->IsRedundant();
//send position and energy to ActorNode for registration as redundant node
string info = "";
info += sIter->globalPos.xCoord;
info += ",";
info += sIter->globalPos.yCoord;
info += ",";
info += sIter->currentEnergy;
sIter->SendMsg<ActorNode>(Message({ info, sIter->id, aIter->id, TYPE2, false }), *aIter);
RedSensorNodeArray.push_back(*sIter);
//direct registration
//if (sIter->isRedundant{ aIter->RegisterRedNode(*sIter); }
}
PrintNodeArray<SensorNode>(RedSensorNodeArray);
for (sIter = RedSensorNodeArray.begin(); sIter != RedSensorNodeArray.end(); sIter++)
{
aIter->InformSensorNodeForMove(*sIter, RedSensorNodeArray);
}
}
}
return 0;
}
template <class T>
vector<T> InitNodeArray(int count)
{
vector<T> actorNodeArray(count);
double x, y;
T aNode;
for (int i = 0; i < count; i++)
{
x = rand() % areaX;
y = rand() % areaY;
aNode = T(i, x, y);
actorNodeArray.push_back(aNode);
}
}
template <class T>
void PrintNodeArray(vector<T> NodeArray)
{
typename vector<T>::iterator iter;
for (iter = NodeArray.begin(); iter != NodeArray.end(); iter++)
{
iter->PrintNodeInfo();
}
}
Other functions are as follows:
InformSensorNodeInRange() in ActorNode.cpp
SendMsg<>(), Broadcast(), and GetNodesInRange() in Node.cpp
ChildNode.h is the header file for ActorNode.cpp and SensorNode.cpp.
Aucun commentaire:
Enregistrer un commentaire