473,394 Members | 1,802 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,394 software developers and data experts.

nested struct array

I am having this problem in a managed c++ DLL which mixes managed and
unmanaged C/C++ code. I tried to assign value to a struct array nested in
another struct. but I can only write to the first element in array, not the
others.

struct struct2{
int a;
int b;
};
struct struct1 //struct with nested struct2 array
{
struct2 item [10];
} ;

void ComboTest(){
struct1 trans;

//nested struct array. nope.

trans.item[0].a = 1; //assign for item[0] is fine

trans.item[0].b = 10; //assign for item[0] is fine

trans.item[1].a = 2; //assign for item[1] does not work.
trans.item[1].b = 20; //assign for item[1] does not work.

//print out trans.

}

The same code seems working fine in C#.

there is no compilation or runtime error. but after the assignment the value
of item[1] just stays unchanged (at default 0s). Is it because nested struct
array is not supported in managed c++? Could anyone shed some light on how to
work around? thanks!
Jan 5 '06 #1
1 4121

"symbol" <sy****@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
I am having this problem in a managed c++ DLL which mixes managed and
unmanaged C/C++ code. I tried to assign value to a struct array nested in
another struct. but I can only write to the first element in array, not
the
others.

struct struct2{
int a;
int b;
};
struct struct1 //struct with nested struct2 array
{
struct2 item [10];
} ;

void ComboTest(){
struct1 trans;

//nested struct array. nope.

trans.item[0].a = 1; //assign for item[0] is fine

trans.item[0].b = 10; //assign for item[0] is fine

trans.item[1].a = 2; //assign for item[1] does not work.
trans.item[1].b = 20; //assign for item[1] does not work.

//print out trans.

}

The same code seems working fine in C#.

there is no compilation or runtime error. but after the assignment the
value
of item[1] just stays unchanged (at default 0s). Is it because nested
struct
array is not supported in managed c++? Could anyone shed some light on how
to
work around? thanks!


Please post C++ questions to the vc NG.

Willy.
Jan 5 '06 #2

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

Similar topics

11
by: Tim | last post by:
Why won't the declaration of a struct array work if I do it like this: 1 typedef struct 2 { 3 int pens; 4 int pencils; 5 } Stationers; 6 .........
1
by: SleepSheep | last post by:
two struct in c# public class A { int i1; byte i2; }
1
by: moondaddy | last post by:
I need to return a nested string array from a function and am getting hung up on syntax. Here's a simple example of a function that returns the array and how I'm trying to call it. Private Sub...
2
by: symbol | last post by:
I am having this problem in a managed c++ DLL which mixes managed and unmanaged C/C++ code. I tried to assign value to a struct array nested in another struct. but I can only write to the first...
2
by: vikerneso | last post by:
I'm trying to sort an array of structs. My code looks something like this: struct Foo { int number; }; int main() {
5
by: GARiMTO | last post by:
Hi there I'm introducting myself in structures in C What i'm trying to do, is create a structure with 3 types like name, age, weight, etc, so i typedef a struct in order to save information for...
2
by: themadme | last post by:
hi, im trying to amke a dynamic struct array with in a struct. Im not entirely sure how to do so. would it be something like this struct foo { }
4
by: Sheldon | last post by:
Hi, I have a unique case where I need an array of structs that grows and within this array is another struct that grows in some cases. I'm having trouble allocating memory. Since I have never...
4
by: mike91 | last post by:
Hello, I have a text file of unknown size that I need to read into a struct array where the struct looks like : { short hours float secondsPastHour float data1 float data2 } But...
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.