Archived

This topic is now archived and is closed to further replies.

DeadlyPencil

Managed c++, arrays

Recommended Posts

iam doing a compression program for school, and i wanna take my bitmap and store it in an array. so what i tried is this ''a'' is a bitmap __gc struct Pixel { int R; int G; int B; }; Pixel* Frame __gc[,]; Frame = new Pixel* __gc [a->Width,a->Height]; now this compiles... but when i got like Frame[0,0]->R = 0; it says its object reference not set to an instance of an object so obviously iam not declaring it right. can anyone help me? iam using visual studios .Net by the way

Share this post


Link to post
Share on other sites
You''re only declaring an array of pointers (or object references in this case). But those references don''t actually reference instances, like they need to. You need to use a loop or similar structure to have each reference point to an actual instance of Pixel.

Share this post


Link to post
Share on other sites
k someone else found the answer for me

__value struct Pixel
{
int R;
int G;
int B;
};

Pixel Frame __gc[,];

Frame = new Pixel __gc[a->Width,a->Height];

Frame[i,j].R =0;

Share this post


Link to post
Share on other sites
...that would also solve your problem, but only skirts the larger issue. In languages like Java all object types are inherently references, so you would have to explicitly create each instance. Just so you know.

Share this post


Link to post
Share on other sites