I have been trying to initialize 1 vector and 1 map in a class.
So to put it simply, once the class or rather a new object has been created, a vector and a map will then be generated or initialized to be able to store items.
How can i actually go about doing it? I am rather clueless and have not found any source on how will i be able to do this. Help is appreciated.
In Nodes.H
class nodes
{
friend ostream &operator<<(ostream &, const nodes&);
vector<string> dataItemsVec;
map<int,int> fingertable;
private:
int nodeNum; // node number
string dataItems; // data items
public:
nodes();
nodes(int, string) : dataItemsVec(){} && fingertable(){}; // i am not sure how to do it
~nodes();
}
In Nodes.cpp
#include "nodes.h"
ostream &operator<<(ostream &printout, const nodes &node)
{
printout<< node.nodeNum << endl;
return printout;
}
nodes::nodes()
{
nodeNum = 0;
dataItems = "";
}
nodes::nodes(int nodeNum,string dataItems)
{
this->nodeNum=nodeNum;
this->dataItems=dataItems;
}
Upon initializing this new object called ‘nodes’.
A vector will be initialized with 0 values to store dataItems.
A map will be initialized with 0 values to store other variables.
You don’t need to do anything. The default constructor for
vectorandmapcause them to be correctly initialised.