Error dereferencing nested STL containers

I'm pretty rusty in my C ++ and that I don't know much about STL. I especially try to read generated volume messages.

Given:

typedef map<string,int>layerType;
typedef vector<layerType> aggregateLayersType;

What happened with:

bool LayerManager::use_layers(aggregateLayersType& layers)
{
  int layerVal = layers[0]["ts"];
} 

Error:

> No viable overloaded operator[] for type
> 'std::__debug::map<std::basic_string<char, std::char_traits<char>,
> std::allocator<char> >, 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> >, int> > >'

I am sure that it will be something simple if someone notes the obvious.

+3
source share
1 answer

It looks like you are using the debug version (std :: __ debug :: map) of the std :: map class: http://gcc.gnu.org/onlinedocs/gcc-4.6.3/libstdc++/api/a00298.html

which is not enough overloaded operator[]in accordance with the documentation.

While it is present in the release version: http://gcc.gnu.org/onlinedocs/gcc-4.6.3/libstdc++/api/a00601.html

typedef std::

typedef std::map<string,int> layerType;

, , std:: __ debug....

+4

All Articles