Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ STL unordered_map problems and doubts

after some years in Java and C# now I'm back to C++. Of course my programming style is influenced by those languages and I tend to feel the need of a special component that I used massively: the HASH MAP. In STL there is the hash_map, that GCC says it's deprecated and I should use unordered_map. So I turned to it. I confess I'm not sure of the portability of what I am doing as I had to use a compiler switch to turn on the feature -std=c++0x that is of the upcoming standard. Anyway I'm happy with this. As long as I can't get it working since if I put in my class

std::unordered_map<unsigned int, baseController*> actionControllers;

and in a method:

void baseController::attachActionController(unsigned int *actionArr, int len,
        baseController *controller) {
    for (int i = 0; i < len; i++){
        actionControllers.insert(actionArr[i], controller);
    }
}

it comes out with the usual ieroglyphs saying it can't find the insert around... hints?

like image 607
gotch4 Avatar asked Nov 28 '22 03:11

gotch4


1 Answers

insert takes a single argument, which is a key-value pair, of type std::pair<const key_type, mapped_type> . So you would use it like this:

actionControllers.insert(std::make_pair(actionArr[i], controller));
like image 85
Mike Seymour Avatar answered Dec 10 '22 12:12

Mike Seymour