Array of structures in C++ .NET

N

ned

I have been having a lot of problems with an array of structures
embedded in another structure in C++ .NET and have boiled it down to
this very simple example:

Try the following steps, it will only take 5 minutes:

1) Create a new C++ .NET Windows Form project.

2) Create a new .h file and put in it:

typedef struct _mini
{
int iVal;
} miniStruct;

typedef struct _test
{
miniStruct mini[10];
} testStruct;


3) In the form1.h file, include the .h file you just created.

4) In the form1.h file Form_Load procedure:

testStruct test;
test.mini[0].iVal = 11;
test.mini[1].iVal = 22;


Please tell me why test.mini[1].iVal does not get set to 22. It is
always 0.

Does this have anything to do with the structures being an unmanaged
(native) C++? I am just learning about managed code and .NET, coming
from a Visual C++ world. I am trying currently to make the structs
above managed structs but having a lot of trouble trying to figure out
how to do an embedded array of structures in another structure using
the managed extensions.

Any help you can give would be greatly appreciated.

thank you.
 
J

James Park

I followed your directions, and added the line

MessageBox::Show(test.mini[1].iVal.ToString());

after the assignments, but it shows 22. What are you doing to get 0?

MessageBox::Show
 
N

ned

James Park said:
I followed your directions, and added the line

MessageBox::Show(test.mini[1].iVal.ToString());

after the assignments, but it shows 22. What are you doing to get 0?

MessageBox::Show


Yes you are right. The message box does show 22.

Where it showed 0 was in the debugger. If you debug through the code,
and put your cursor over test.mini[1].iVal, it shows 0. When you
Quickwatch 'test', it shows that test.mini[1].iVal is 0. Why?

Thanks for your reply,

ned
 
J

James Park

ned said:
James Park said:
I followed your directions, and added the line

MessageBox::Show(test.mini[1].iVal.ToString());

after the assignments, but it shows 22. What are you doing to get 0?


Yes you are right. The message box does show 22.

Where it showed 0 was in the debugger. If you debug through the code,
and put your cursor over test.mini[1].iVal, it shows 0. When you
Quickwatch 'test', it shows that test.mini[1].iVal is 0. Why?

Thanks for your reply,

ned

It looks like a bug:
http://www.dotnet247.com/247reference/msgs/44/222866.aspx

And that Ken Bayer guy speaks the truth as VS 2005 Beta 2 does not suffer
the same problem. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top