(Newbie problem) Setting array values?

meretrix

Member
Joined
Aug 14, 2003
Messages
13
test = new Byte[1600];
for (int i=0; i<40; i++)
for (int j=0; j<40; j++)
test->SetValue(0x0A, (j*40)+i);

gives the error: "void System::Array::SetValue(System::Object __gc*, int): cannot convert parameter 1 from int into System::Object __gc* "

How do you set the values of an array?
 
Now it spits a new error at me...

[ : Cannot perform pointer arithmetic on __gc pointer System::Array __gc*

(Thats what I tried to begin with, by the way... Ive done plenty of C programming, but this managed C++ stuff is totally new to me.)
 
You need to box the object into a managed object.
Code:
test->SetValue(__box(0x0A), (j*40)+i);
You may need to do it more like this.
Code:
int val = 0x0A;

test->SetValue(__box(val), (j*40)+i);
Since Im not sure if __box will work on straight values rather than variables or objects.
 
Back
Top