473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

My Funky Pass By Reference Issue

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++
..dlu!std::list<HWND__ *,std::allocator<HWND__ *>
>::_Assign<std::list<HWND__ *,std::allocator<HWND__ *>
::_Const_iterator<1(std::list<HWND__ *,std::allocator<HWND__ *>
::_Const_iterator<1_First=0xcdcdcdcd {unused=??? },
std::list<HWND__ *,std::allocator<HWND__ *::_Const_iterator<1>
_Last=0xcdcdcdcd {unused=??? }, std::input_iterator_tag
__formal={...}) Line 678 C++
..dlu!std::list<HWND__ *,std::allocator<HWND__ *>
>::assign<std::list<HWND__ *,std::allocator<HWND__ *>
::_Const_iterator<1(std::list<HWND__ *,std::allocator<HWND__ *>
::_Const_iterator<1_First=0xcdcdcdcd {unused=??? },
std::list<HWND__ *,std::allocator<HWND__ *::_Const_iterator<1>
_Last=0xcdcdcdcd {unused=??? }) Line 666 C++
..dlu!std::list<HWND__ *,std::allocator<HWND__ *::operator=(const
std::list<HWND__ *,std::allocator<HWND__ * & _Right=[0]()) Line
522 C++
..dlu!A::operator=(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::ProjectCurrGet(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-

Jun 17 '07 #1
3 2480
VirGin wrote:
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++
.dlu!std::list<HWND__ *,std::allocator<HWND__ *>
>::_Assign<std::list<HWND__ *,std::allocator<HWND__ *>
::_Const_iterator<1(std::list<HWND__ *,std::allocator<HWND__ *>
::_Const_iterator<1_First=0xcdcdcdcd {unused=??? },
std::list<HWND__ *,std::allocator<HWND__ *::_Const_iterator<1>
_Last=0xcdcdcdcd {unused=??? }, std::input_iterator_tag
__formal={...}) Line 678 C++
.dlu!std::list<HWND__ *,std::allocator<HWND__ *>
>::assign<std::list<HWND__ *,std::allocator<HWND__ *>
::_Const_iterator<1(std::list<HWND__ *,std::allocator<HWND__ *>
::_Const_iterator<1_First=0xcdcdcdcd {unused=??? },
std::list<HWND__ *,std::allocator<HWND__ *::_Const_iterator<1>
_Last=0xcdcdcdcd {unused=??? }) Line 666 C++
.dlu!std::list<HWND__ *,std::allocator<HWND__ *::operator=(const
std::list<HWND__ *,std::allocator<HWND__ * & _Right=[0]()) Line
522 C++
.dlu!A::operator=(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::ProjectCurrGet(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?
Well of course you shouldn't make random changes when you don't
understand the cause of the error. You would just be digging a deeper
hole for yourself.

You seem to have tried every variation on assignment except the correct one

*xProj = tProj;

or is that just a typo in your post?

The other issue that strikes me is the various members you have in your
structs. What types are those? Do they have valid assignment operators
defined? The compiler generated assignment operator should never crash
if all the component parts are correctly assignable.

As usual with these kind of posts, the error is somewhere in the code
you didn't post. If the above doesn't help try posting a bit more. If
you can a small but complete program that demonstrates the error will
get you an answer in no time.

john
Jun 17 '07 #2
Well of course you shouldn't make random changes when you don't
understand the cause of the error. You would just be digging a deeper
hole for yourself.
True. I'm sure you know how it is when one is tired and frustrated.
>
You seem to have tried every variation on assignment except the correct one

*xProj = tProj;
This fails during the copy of the list as well. This was the original
version.

or is that just a typo in your post?
I was in the middle of another attempt when I grabbed the code to
paste for a buddy.

The other issue that strikes me is the various members you have in your
structs. What types are those? Do they have valid assignment operators
defined? The compiler generated assignment operator should never crash
if all the component parts are correctly assignable.
They are basic types and TCHAR. The other members are copied without a
problem.
As usual with these kind of posts, the error is somewhere in the code
you didn't post. If the above doesn't help try posting a bit more. If
you can a small but complete program that demonstrates the error will
get you an answer in no time.
True, I agree.

After creating a small app just to test the functionality, I
discovered it was a call to ZeroMemory (ZeroMemory(&xProject,
sizeof(xProject));) before calling the function to populate the object
(ProjectCurrGet(iTmp, &xProject);).
Thank You for the Kick In The Head.
-V-

Jun 17 '07 #3
>As usual with these kind of posts, the error is somewhere in the code
>you didn't post. If the above doesn't help try posting a bit more. If
you can a small but complete program that demonstrates the error will
get you an answer in no time.

True, I agree.

After creating a small app just to test the functionality, I
discovered it was a call to ZeroMemory (ZeroMemory(&xProject,
sizeof(xProject));) before calling the function to populate the object
(ProjectCurrGet(iTmp, &xProject);).
Hey well done! Good though it is almost no-one posting here takes that
advice. Clearly you've got talent.

john
Jun 17 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Steve Jorgensen | last post by:
I just came up with a really tidy little solution to the VB/VBA circular reference issue. It only works with Access 2000 or newer, but that's about the only down-side. The issue... You need an...
2
by: John Baker | last post by:
Hi: I am developing a report, and have run into a reference snag. I have subtotals which i generate on the report, and have named "tasksum", which represent the number of hours an individual...
4
by: Omar Llanos | last post by:
Recently, I posted a question on how to invoke a textbox control in Form1 (parent form) from within Form2 (which is inherited from Form1). Someone suggested to pass a reference of the Form1 to the...
5
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant...
2
by: Earl | last post by:
I posted this awhile back in the CF forum and got no answer, so I'm posting it here today in hopes that a broader group of developers might nudge me in the right direction. I'm getting a weird...
3
by: John E. | last post by:
I am trying to find a way to not have to reference an object in all my projects, since it is initialized & instantiated in my Common class. I have a 4 tier project (presentation, rules, dal,...
9
by: Stuart Carnie | last post by:
Due to the tightening of the VC++ compiler in 2005, I have run into a compiler error (from code that previously worked in 2003) using a CComPtr<ITypeLib> as an element of a std::list, as follows...
4
by: WXS | last post by:
In a case you have Project/Assembly A references Project/Assembly B which References Project/Assembly C. Let's say Project A needs be and references it directly. Unknown to A, B needs project C's...
2
by: ChrisB | last post by:
Hello, I was wondering what options are available for resolving the following (simplified) scenario. Two project exist and each contains a class: ProjectA - Class1 ProjectB - Class2 ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.