• Advertisement

Archived

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

Managed c++, arrays

This topic is 5145 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
that''s an array of pointers.

what are the pointers pointing to? have you created the pointed to objects?

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

  • Advertisement