mardi 30 juin 2015

Iterating over maps with vectors as a value

I am trying to create a map which takes in a string as a key and has a vector of unsigned ints as its value. One of my functions, takes in this map and is declared as follows:

void setAllDAC(std::map<string, std::vector<unsigned int> > dacs){
    //program the control register
    progdac(dacs[k_DACName_ChipContReg][1],dacs[k_DACName_ChipContReg][0]);
    //make iterator
    std::map<std::string, std::vector<unsigned int> > ::iterator it;
    for(it = dacs.begin(); it !=dacs.end(); it ++){
        std::string stmp = it ->first;
        std::vector vtmp = it ->second;
            if(stmp != k_DACName_ChipContReg){
                progdac(vtmp[1],vtmp[0]);
            }
    }
}

Where the header of the function progdac is as follows:

int progdac(int dacaddress, int dacvalue)

When I try to compile this program I get the following error:

src/common/PixelFECInterface.cc:2674: error: no match for ‘operator=’ in ‘it >=...

and

src/common/PixelFECInterface.cc:2670: error: passing ‘const std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned int, std::allocator<unsigned int> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned int, std::allocator<unsigned int> > > > >’ as ‘this’ argument of ‘_Tp& std::map

I should also point out that line 2670 corresponds to the call to progdac and line 2674 corresponds to the for loop. What exactly is wrong with the code?

Aucun commentaire:

Enregistrer un commentaire