Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

STL nested containers dereferencing error

I'm pretty rusty in my C++ and what little STL knowledge I once had. I'm particularly struggling to read the voluminous error messages generated.

Given:

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

What's wrong with:

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

The error is:

> 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'm sure it's going to be something simple once someone points out the obvious.

like image 243
wadesworld Avatar asked Dec 02 '25 14:12

wadesworld


1 Answers

It looks like you're 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 lacks the overloaded operator[] according to the documentation.

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

Try prefixing your map typedef with std::

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

I suspect that their might be some namespace leakage elsewhere in your code where std::__debug is leaked ....

like image 75
sashang Avatar answered Dec 04 '25 03:12

sashang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!