nested struct array not supported in .net 1.1 managed c++?

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.

}


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

Carl Daniel [VC++ MVP]

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

How are you concluding that item[1] wasn't modified?

-cd
 
M

Marcus Heege

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.

}


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!

I cannot reporduce your problem. The code below compiles and works with
VC2003 and VC2005.

Marcus Heege
www.heege.net

<code language="C++/CLI" filename="test.cpp" compileWith="CL /clr test.cpp">
#using <mscorlib.dll>

struct struct2{
int a;
int b;
};


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

int main()
{
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.

System::Console::WriteLine(trans.item[1].a);
System::Console::WriteLine(trans.item[1].b);
}
</code>
 

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