I have an error in map iterators. The problem is the following:
class JacobianCol
{
private:
...
JacobianColData::iterator _L_begin;
public:
JacobianColData::iterator L_begin();
...
};
In another module:
JacobianCol LUSolver::col_subtract(const JacobianColData::iterator &alpha, JacobianCol &X, JacobianCol &Y)
{
JacobianCol result = Y;
//alternate "result" variable
return result;
}
Call:
...
J[*it] = col_subtract(friend_element, J[diag_index], J[*it]);
...
And when I assign result of col_subtract to J[*it] I get J[*it].L_begin pointing to a deallocated memory (pointer to a previous J[*it]).
JacobianCol has the _col_data member. i.e, the input instance JacobianCol Y has a _col_data instance and _L_Begin of this is initialized with that map’s iterator. When you return the result, a different _col_data member is created. Now, the _L_Begin iterator is copied from the original Y instance. That is why you get the observed behavior.
To resolve this implement the copy constructor, copy the map and the re-initialize the iterator by explicitly calling _col_data.begin() in the copy constructor