Hi,
in the following piece of code I need to iterate through a vector to
create a map that has as key type the pointer to an object of the
UserEquipment class and as value type size_t.
The problem I encountered is that even if the address of the pointer to
the UserEquipment (in the code it is pActiveUe) changes inside the
cycle, the key doesn't seem to change because the previous value is
overwritten with the new value instead of a new element being added to
the map. Can anyone explain why?
Thanks.
vector<Connection*>& rpActiveConnections =
mpSector->GetrActiveConnections();
if ( !rpActiveConnections.empty() ) {
// in the header: map<UserEquipment*, size_t> mNumOfFreqSlotsToAdd;
mNumOfFreqSlotsToAdd.clear();
UserEquipment* pActiveUe;
double scalingFactor;
size_t numOfFreqSlotsToRemove;
for (vector<Connection*>::iterator activeConIt =
rpActiveConnections.begin();
activeConIt != rpActiveConnections.end(); ++activeConIt) {
pActiveUe = (*activeConIt)->GetpUserEquipment();
vector<int>& rAllocatedFreqSlotsForUe =
pActiveUe->GetrAllocatedFrequencySlots();
if ( pActiveUe->GetUplinkSinr_l() > mSinrTarget_l +
pActiveUe->GetPowerStep_l() ) {
scalingFactor = pActiveUe->GetUplinkSinr_l() /
mSinrTarget_l;
}
else {
scalingFactor =
pActiveUe->GetMaxTransmitPower_W()/pActiveUe->GetTransmitPower_W();
}
// the following instruction is my problem
mNumOfFreqSlotsToAdd[pActiveUe] =
(size_t)ceil( rAllocatedFreqSlotsForUe.size() *
(scalingFactor-1) );
cout << "mNumOfFreqSlotsToAdd has size "<<
mNumOfFreqSlotsToAdd.size() << endl;
}
}