Q:

C++ pass STL container items as reference

I have a map of type std::map<std::string, std::vector<MyClass>>.  The map is filled in this way that I create a vector and put it with a guid as a pair  into the map.  Then I want to call a function, give the just inserted vector to it and let it fill the vector.  It looks like that:
{
    std::string guid = "aGUID"
    std::vector<MyClass> vec_myClass(0);
    my_map[guid] = vec_myClass;
    std::vector<MyClass>& vec_ref = my_map[guid];

    FillVector(vec_ref);    
}

FillVector(std::vector<MyClass>& vec)  { vec.push_back(...); }

I think the [] operator returns a reference of the item in my_map, which I can give to a function to work with it, but my application crashes at this point.  I am putting the vector first into the map (when it is empty) because I want to avoid copying effort as function FillVector puts lots of items into the vector.  Where is my mistake?  Might it be wrong to pass a reference by reference to a function?  Or is there a clearly better solution to this?  I prefer references over pointers here.  Thx, and all the best. 

A:

All that code simplifies to:
{
    std::string guid = "aGUID"
    FillVector(my_map[guid]);    
}

Btw.  I think your problem does not appear to be here, but in code you don't show us...

