468,512 Members | 1,606 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

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 3935

"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Tim | last post: by
2 posts views Thread by vikerneso | last post: by
5 posts views Thread by GARiMTO | last post: by
4 posts views Thread by Sheldon | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.