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 (i.e. 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 (e.g. compiler and standard library writers).

You just want to use

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

... to access the elements of the iterator.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top