I'm trying to create a map reference which should containt a pair as a key and a bool vector as the value i.e. such a thing
map<pair<int,int> * ,vector<bool>* >* linkWaveMapping = new map<pair<int,int>*, vector<bool>*>;
It seems I cannot correctly make a pair with some int's :
1 2 3
int srcAddr= 1;
int destAddr= 2;
pair<int,int>* thePair = new pair(srcAddr,destAddr);
yields the following
Description Resource Path Location Type cannot convert 'int*' to 'std::pair<int, int>*' in initialization PCE_CHILD.cc /geysers_simulator/src/Network line 784 C/C++ Problem
and
Description Resource Path Location Type
expected ',' or ';' before 'pair' PCE_CHILD.cc /geysers_simulator/src/Network line 784 C/C++ Problem
and
Description Resource Path Location Type
expected type-specifier before 'pair' PCE_CHILD.cc /geysers_simulator/src/Network line 784 C/C++ Problem
Also I cannot add to the map (bitmapToSend is a bool vector created correctly):
There is no type deduction with template types so you always need to specify the types. pair<int,int>* thePair = new pair<int,int>(srcAddr,destAddr);
It looks like you use a lot of pointers everywhere. Is this really necessary? The code usually gets much more clean if you try to avoid pointers when not necessary.
indeed I saw the solution of the first problem while review the code for the second time. Thanks for this.
To answer your second question: I do need these pointers, as I'm using the Omnet simulator and I need to exchange messages between objects with some information and that information is to be stored in pointers.
The second question still remains unsolved for me.
insert takes as argument a pair (not a pointer to a pair) with the key as first and value type as second element.
I think this is correct but as you can see, it gets quite unreadable. linkWaveMapping->insert(pair<pair<int,int>*,vector<bool>* >(thePair,bitmapToSend));
To make it a bit more readable you can use the function make_pair. linkWaveMapping->insert(make_pair(thePair,bitmapToSend));
I still think you are overusing pointers by the way. If you didn't know, you can get references/pointers to objects not allocated with new. There is rarely a good reason to allocate containers with new as you do with the map.
What does "Not working code" mean? Not compile or logic?
There is a difference between insert and the operator[]. Insert will not insert the value if it is there already and operator[] will over write the value with the new one.
"Because map containers do not allow for duplicate key values, the insertion operation checks for each element inserted whether another element exists already in the container with the same key value, if so, the element is not inserted and its mapped value is not changed in any way."
I solved the issue indeed as Peter87 suggested by limiting the Pointer usage. I needed a pointer for the linkWaveMapping but as turns out by inserting key-value pairs copies of these keys-pairs are made and are stored for the life time of the container's life. So I did not need to have the key value pairs as pointers.