简体   繁体   中英

unordered_set from std

I have to rewrite windows-code into crossplatform view. Here is the example:

std::unordered_set<Type>::iterator it = ...;
it._Ptr->_Myval->...

Everywere in code there is _Ptr member in iterator but I can't find it in docs. I think it works with visual studio (it's implementation of stl). Any ideas how to replace it? And what is _Myval ?


UPD:

for(std::unordered_set<QuadTreeOccupant*>::iterator it = ...)
   it->aabb;

class QuadTreeOccupant
{
   public:
      AABB aabb;
};

And the error at line it->aabb :

error: request for member 'aabb' in '* it.std::__detail::_Hashtable_iterator<_Value, __constant_iterators, __cache>::operator-> with _Value = qdt::QuadTreeOccupant*, bool __constant_iterators = true, bool _ cache = false, std:: _detail::_Hashtable_iterator<_Value, __constant_iterators, __cache>::pointer = qdt::QuadTreeOccupant* const*', which is of non-class type 'qdt::QuadTreeOccupant* const'

Those are implementation details of unordered_map specific to VC's implementation. You should just remove the reference to _Ptr and _Myval and use either of:

  • it->
  • (*it).

in place of it._Ptr->_Myval.

As for the update: the iterator is "like a pointer" to the element, so *it refers to the contained element; but , you can't access the members of your elements using it-> , since your member element is a pointer, and thus an iterator is "like" a double pointer.

Long story short, you have to do:

(*it)->aabb;

since *it gives you a QuadTreeOccupant* , and you can then access its members via the -> operator.

---edit---

too late...

The _Ptr looks like an implementation detail which you shouldn't have access to (ie it should probably be `private) and you shouldn't use in any case: names starting with an underscore and followed by a capital letter are a no-go area for everybody except people explicitly invited in. These are just implementers of the C++ system (eg compiler and standard library writers).

You just want to use

it->...
(*it). ...

... to access the elements of the iterator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM