Weird errors with std::map
Hi. I'm using a std::map to store font glyphs so that I can look them up by character. (Can't simply use an array since I use unicode characters.)
Anyway, when I try to do the following:
GCC gives me this long and incomprehensible STL error message:
It seems to me that the compiler is looking for a overloaded ternary operator (weird, because I didn't think the ternary operator was overloadable in C++), or that the result of "(m_glyphs.end() == itr)" isn't a bool, which it surely should be.
All the Glyph structures and typedefs follow.
If anyone can see the problem here, please let me know.
Anyway, when I try to do the following:
Code:
GlyphMapConstItr itr = m_glyphs.find(c);
GlyphMetrics& m = (m_glyphs.end() == itr) ? m_unkownGlyph : *itr;GCC gives me this long and incomprehensible STL error message:
Quote:/Path/to/File.cpp:164: error: no match for ternary 'operator?:' in '((const Qoph::Font*)this)->Qoph::Font::m_glyphs. std::map<_Key, _Tp, _Compare, _Alloc>::end [with _Key = wchar_t, _Tp = Qoph::Font::GlyphMetrics, _Compare = std::less<wchar_t>, _Alloc = std::allocator<std::pair<const wchar_t, Qoph::Font::GlyphMetrics> >]().std::_Rb_tree_const_iterator<_Tp>::operator== [with _Tp = std::pair<const wchar_t, Qoph::Font::GlyphMetrics>](((const std::_Rb_tree_const_iterator<std::pair<const wchar_t, Qoph::Font::GlyphMetrics> >&)((const std::_Rb_tree_const_iterator<std::pair<const wchar_t, Qoph::Font::GlyphMetrics> >*)(& itr)))) ? ((const Qoph::Font*)this)->Qoph::Font::m_unkownGlyph : itr. std::_Rb_tree_const_iterator<_Tp>::operator* [with _Tp = std::pair<const wchar_t, Qoph::Font::GlyphMetrics>]()'
It seems to me that the compiler is looking for a overloaded ternary operator (weird, because I didn't think the ternary operator was overloadable in C++), or that the result of "(m_glyphs.end() == itr)" isn't a bool, which it surely should be.
All the Glyph structures and typedefs follow.
Code:
struct GlyphMetrics {
Vector2i position;
Vector2i size;
Vector2i origin;
int advance;
};
typedef std::map<wchar_t, GlyphMetrics> GlyphMap;
typedef GlyphMap::iterator GlyphMapItr;
typedef GlyphMap::const_iterator GlyphMapConstItr;
GlyphMap m_glyphs;
GlyphMetrics m_unkownGlyph;If anyone can see the problem here, please let me know.
Is GlyphMapConstItr your own class/subclass, or is it just a typedeffed Map<types>::iterator? If the former, then you may have to make sure that you overload operator ==, and make sure that it takes Map<types>::iterator. If the latter, then I don't know, since it should already have operator == overloaded correctly. (I'm pretty sure the operator == is somehow the root of your problem, though)
GlyphMapConstItr is defined as:
Code:
typedef std::map<wchar_t, GlyphMetrics> GlyphMap;
typedef GlyphMap::const_iterator GlyphMapConstItr;
It's a const iterator, therefore you can't modify what it points to. I think this should work:
Code:
const GlyphMetrics& m = (m_glyphs.end() == itr) ? m_unkownGlyph : *itr;
Thanks OneSadCookie. Tha was one of the problems. The other was that
... : *itr;
should have been
... : (*itr).second;
since a std::map iterator points to a std :: pair.
Sometimes I feel really stupid. although, in my defense, the error message wasn't the world's most helpful.
Thank you all for the help.
... : *itr;
should have been
... : (*itr).second;
since a std::map iterator points to a std :: pair.
Sometimes I feel really stupid. although, in my defense, the error message wasn't the world's most helpful.
Thank you all for the help.
Just for the record, using the form itr->second instead of (*itr).second seems cleaner.
I'm not sure iterators are guaranteed to provide ->, where they are guaranteed to provide *... but I can't remember why I might think this
OneSadCookie Wrote:I'm not sure iterators are guaranteed to provide ->, where they are guaranteed to provide *... but I can't remember why I might think thisI have no idea why you think that, iirc both * and -> are valid for dereferencing an iterator, and I don't recall reading -> was optional: http://www.sgi.com/tech/stl/trivial.html
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| weird compiler warnings/errors in Xcode 2.0 | Andrew | 15 | 6,107 |
May 13, 2005 01:07 AM Last Post: Andrew |
|

