
On Mon, May 2, 2011 at 22:04, Craig Longman <craigl@longmanhouse.ca> wrote:
I'm using VS v9, just in case that matters in this case.
unordered_map< string, uint32_t > xrf1; unordered_map< string, uint32_t >::const_iterator& iter = xrf1.find( "hello" );
This is something I've used many times with the other containers (well, std::map at least), but here I'm getting a conversion error.
VS is letting you do something not standards-compliant. You're trying to bind a temporary to a reference-to-nonconst, which is illegal. Try to do the same thing in a non-VS compiler with std::map and you'll see it fail: #include <map> #include <string> using namespace std; int main() { map< string, int > xrf1; map< string, int >::const_iterator& iter = xrf1.find( "hello" ); } In function 'int main()': Line 7: error: invalid initialization of non-const reference of type '__gnu_debug::_Safe_iterator<std::_Rb_tree_const_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char>
, int> >, __gnu_debug_def::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> > > >&' from a temporary of type '__gnu_debug::_Safe_iterator<std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> , int> >, __gnu_debug_def::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> > > >'
~ Scott