V
VirGin
I am passing an object by reference to a function that is supposed to
populate it with current data.
Both the destination object and the source have nested std::lists,
some branches of the lists might be empty.
The function crashes when copying the lists, the error info is:
..dlu!std::list<HWND__ *,std::allocator<HWND__ *> >::clear() Line 818
+ 0xf bytes C++
_Last=0xcdcdcdcd {unused=??? }, std::input_iterator_tag
__formal={...}) Line 678 C++
_Last=0xcdcdcdcd {unused=??? }) Line 666 C++
..dlu!std::list<HWND__ *,std::allocator<HWND__ *> >:
perator=(const
std::list<HWND__ *,std::allocator<HWND__ *> > & _Right=[0]()) Line
522 C++
..dlu!A:
perator=(const A & __that={...}) + 0xf2 bytes C++
void clear()
{ // erase all
#if _HAS_ITERATOR_DEBUGGING
this->_Orphan_ptr(*this, 0);
#endif /* _HAS_ITERATOR_DEBUGGING */
_Nodeptr _Pnext;
_Nodeptr _Pnode = _Nextnode(_Myhead);
The structure of the source and destination is roughly:
struct C
{
member
member
}
struct B
{
member
member
std::list<B>
std::list<C>
}
struct A
{
member
member
std::list<B>
}
std::list <A>
A::member
A::member
A::std::list<B>
B::member
B::member
B::std::list<B>
B::std::list<C>
C::member
C::member
// Function to return a copy of type A
void ClassName:
rojectCurrGet(UINT iVal, A *xProj)
{
std::list<A>::iterator ProjIter;
std::list<A>::size_type tProjSize;
A tProj;
A tProj2; //Test
ProjIter = xProjects.begin();
while(ProjIter != xProjects.end())
{
tProj = (*ProjIter);
if (iVal == tProj.TabNum)
{
// straight assignment test
tProj2 = tProj;
xProj = tProj; // This crashes on the embedded list
// xProj = &(tProj);
// *xProj = *ProjIter;
// *xProj = *(ProjIter);
// *xProj = (*ProjIter);
// This works, but all I'm doing is assigning the *local* 'copy' /
address to xProj. When the function ends, the stack is hosed and xProj
points at nothing.
// xProj = &(*ProjIter);
break;
}
// ZeroMemory(&tProj, sizeof(tProj));
ProjIter++;
}
return;
}
The Source is a member of ClassName:
A xProject;
The Destination is type A.
It is being called as so:
ProjectCurrGet(iTmp, &xProject);
It is only when the function assigns the copy from the std::list to
the target (which was passed by reference) that it fails.
The assignment to a local copy of A works without a problem.
My last idea is to overload the assignment operator of A. I'm hesitant
to do this but if that is my only option, I will.
Any suggestions?
-V-
populate it with current data.
Both the destination object and the source have nested std::lists,
some branches of the lists might be empty.
The function crashes when copying the lists, the error info is:
..dlu!std::list<HWND__ *,std::allocator<HWND__ *> >::clear() Line 818
+ 0xf bytes C++
std::list<HWND__ *,std::allocator<HWND__ *> >::_Const_iterator<1>..dlu!std::list said:::_Assign<std::list<HWND__ *,std::allocator<HWND__ *>
::_Const_iterator<1> >(std::list<HWND__ *,std::allocator<HWND__ *>
::_Const_iterator<1> _First=0xcdcdcdcd {unused=??? },
_Last=0xcdcdcdcd {unused=??? }, std::input_iterator_tag
__formal={...}) Line 678 C++
std::list<HWND__ *,std::allocator<HWND__ *> >::_Const_iterator<1>..dlu!std::list said:::assign<std::list<HWND__ *,std::allocator<HWND__ *>
::_Const_iterator<1> >(std::list<HWND__ *,std::allocator<HWND__ *>
::_Const_iterator<1> _First=0xcdcdcdcd {unused=??? },
_Last=0xcdcdcdcd {unused=??? }) Line 666 C++
..dlu!std::list<HWND__ *,std::allocator<HWND__ *> >:
std::list<HWND__ *,std::allocator<HWND__ *> > & _Right=[0]()) Line
522 C++
..dlu!A:
void clear()
{ // erase all
#if _HAS_ITERATOR_DEBUGGING
this->_Orphan_ptr(*this, 0);
#endif /* _HAS_ITERATOR_DEBUGGING */
_Nodeptr _Pnext;
_Nodeptr _Pnode = _Nextnode(_Myhead);
The structure of the source and destination is roughly:
struct C
{
member
member
}
struct B
{
member
member
std::list<B>
std::list<C>
}
struct A
{
member
member
std::list<B>
}
std::list <A>
A::member
A::member
A::std::list<B>
B::member
B::member
B::std::list<B>
B::std::list<C>
C::member
C::member
// Function to return a copy of type A
void ClassName:
{
std::list<A>::iterator ProjIter;
std::list<A>::size_type tProjSize;
A tProj;
A tProj2; //Test
ProjIter = xProjects.begin();
while(ProjIter != xProjects.end())
{
tProj = (*ProjIter);
if (iVal == tProj.TabNum)
{
// straight assignment test
tProj2 = tProj;
xProj = tProj; // This crashes on the embedded list
// xProj = &(tProj);
// *xProj = *ProjIter;
// *xProj = *(ProjIter);
// *xProj = (*ProjIter);
// This works, but all I'm doing is assigning the *local* 'copy' /
address to xProj. When the function ends, the stack is hosed and xProj
points at nothing.
// xProj = &(*ProjIter);
break;
}
// ZeroMemory(&tProj, sizeof(tProj));
ProjIter++;
}
return;
}
The Source is a member of ClassName:
A xProject;
The Destination is type A.
It is being called as so:
ProjectCurrGet(iTmp, &xProject);
It is only when the function assigns the copy from the std::list to
the target (which was passed by reference) that it fails.
The assignment to a local copy of A works without a problem.
My last idea is to overload the assignment operator of A. I'm hesitant
to do this but if that is my only option, I will.
Any suggestions?
-V-