I am writing a 3D mesh for my scientific software, and I need to iterate through the nodes of the mesh to get their coordinates. Instead of holding each node object in the container, I'd rather just calculate the coordinates on the fly during the iteration. The problem is that stl :: iterator requires returning a reference to the value as a result of operator*() or a pointer to operator->() .
Some of the code below:
class spGridIterator { public: typedef forward_iterator_tag iterator_category; typedef spVector3D value_type; typedef int difference_type; typedef spVector3D* pointer; typedef spVector3D& reference; spGridIterator(spGrid* gr, int index); spGridIterator& operator++(); spGridIterator& operator++(int); reference operator*() const; pointer operator->() const; private: spGrid* m_grid; int m_idx; };
spGridIterator::reference spGridIterator::operator*() const { // return m_grid->GetPoint(m_idx); } spGridIterator::pointer spGridIterator::operator->() const { // return m_grid->GetPoint(m_idx); }
This method retrieves node coordinates by index
spVector3D spGrid::GetPoint(int idx) const {
Any input on this?
Thanks in advance, Ilya
source share