nested struct array

G

Guest

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!
 
W

Willy Denoyette [MVP]

symbol said:
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.
 

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