mercredi 3 août 2016

c++ get a vector from a map of vectors

I have a map of vector

map< int, vector<float> > hit = getAlignedHits();

I want to get the vector paired with a specific key, such as:

vector<float> vec;
vec = hit[1];

The error I get is:

candidate function not viable: no known conversion from 'vector>' to 'const vector>' for 1st argument vector& operator=(const vector& __x);

I tried below, didn't work:

    &vec =  hit[1];

error: expression is not assignable

I also tried below, didn't work:

    map< int, vector<float> >::iterator itr;
    itr = hit.find(1);
    &vec =  itr->second;

error: expression is not assignable

Does anyone know why these doesn't work, and how I can get the vector from the map?

Thanks a lot in advance

Aucun commentaire:

Enregistrer un commentaire