473,387 Members | 2,436 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,387 software developers and data experts.

Array of structures in C++ .NET

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.

Nov 17 '05 #1
4 4865
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
"ned" <nd*****@apt-research.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
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.

Nov 17 '05 #2
ned
"James Park" wrote:
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

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 17 '05 #3
"ned" <nd*****@apt-research.com> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
"James Park" wrote:
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/247referenc...44/222866.aspx

And that Ken Bayer guy speaks the truth as VS 2005 Beta 2 does not suffer
the same problem. :)
Nov 17 '05 #4
ned

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

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

Hours of wasted debugging time is right!
Thanks so much for referencing the article,
ned
--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 17 '05 #5

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

Similar topics

8
by: michi | last post by:
Hello everybody, I have following problem: I have an array of pointers to structures: table* tab = new table; and structure table is like this: struct table{ CSLL::node* chain;
4
by: emma middlebrook | last post by:
Hi Straight to the point - I don't understand why System.Array derives from IList (given the methods/properties actually on IList). When designing an interface you specify a contract. Deriving...
8
by: ulyses | last post by:
I'm trying to put pointer to flexible array of structures in other structure. I want to have pointer to array of pixels in screen structure. Here is mine code, but I think it isn't quite all right:...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: Sam | last post by:
Hello I have a structure called Company. struct Company { char *employee; char *employee_address; }; I want to build an array of this structure but the number of employees will change...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
11
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
44
by: svata | last post by:
Hello, I wonder how to resize such array of structures using realloc()? #include <stdio.h> #include <stdlib.h> #define FIRST 7 typedef struct { char *name;
17
by: Ben Bacarisse | last post by:
candide <toto@free.frwrites: These two statements are very different. The first one is just wrong and I am pretty sure you did not mean to suggest that. There is no object in C that is the...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.