STL - Debug assertion failure, vector iterator not dereferencable
I recently converted a visual studio .net project to visual studio 2005
project. After
the conversion I am now having runtime errors on a collection that is
composed of a vector of CComVariants.
std::vector<CComVariant> m_vecResults;
More specifically it gives me a Debug assertion failure, vector iterator
not dereferencable in my get__NewEnum method on the Init statement in the
following
code;
STDMETHODIMP get__NewEnum(IUnknown** ppUnk)
{
typedef CComObject<CComEnum<IEnumVARIANT, &IID_IEnumVARIANT,
VARIANT, _Copy<VARIANT> > > enumVariant;
enumVariant* pEnum = new enumVariant;
HRESULT hr = pEnum->Init(&*m_vecResults.begin(),
&*m_vecResults.end(),
0,
AtlFlagCopy );
...
...
...
}
So I modified my code to the following the following to not use begin/end
and it
seemed to of fix the problem.
STDMETHODIMP get__NewEnum(IUnknown** ppUnk)
{
typedef CComObject<CComEnum<IEnumVARIANT, &IID_IEnumVARIANT,
VARIANT, _Copy<VARIANT> > > enumVariant;
size_t nSize = m_vecResults.size();
enumVariant* pEnum = new enumVariant;
HRESULT hr = pEnum->Init(&m_vecResults[0], &m_vecResults[nSize-1],
NULL,
AtlFlagCopy);
...
...
...
}
Now I have another piece of code that uses a priority queue;
typedef priority_queue< CRfItem, vector< CRfItem >, CRfItem::greater >
RfQueue;
RfQueue m_QueueAllPoints;
I am experiencing the same error again in the following code segment on the
top()
statment;
RfQueue::value_type temp = m_QueueAllPoints.top();
m_VectorFit.push_back(temp);
m_QueueAllPoints.pop();
This have been using this code for several months, without error until I
converted it to visual studio 2005. Is there an error within the new version
of the STL or have they improved the error handling?