+2  A: 

You could use a member variable to hold the grid point it is currently pointing to:

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;
    spVector3D CurrentPoint;
};

Then the dereference operator could look like this:

spGridIterator::reference spGridIterator::operator*() const {
    CurrentPoint = m_grid->GetPoint(m_idx);
    return CurrentPoint;
}
Space_C0wb0y
+1  A: 

Since an iterator is a value object, why not just setting a member to the value you want to return, and return a reference to the member?

Jan
+1  A: 

Short answer is, this will lead to undefined behaviour, you are after all returning a reference to a temporary! One option (if this iterator does not have to re-entrant is to have a class member (of type spVector3D) to which you "assign" the returned value (of course you could do it more optimally by passing in a reference to this to GetPoint as well as index), and then return that.

Nim
Thanks for your response too!
ezpresso