Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

struct access violation

Status
Not open for further replies.

iandobrien

Programmer
May 2, 2002
7
IE
Hi,
just wondering if anyone might be able to help me out with this problem im having using structs in C++. I am trying to add a number to a 2D array that is a member of the struct but i am getting an "access violation" at runtime..Below is the code..thanks

typedef struct
{
unsigned int **red;

}rgbimage;

//and then i declare the struct..
rgbimage* image;

//and further down in my code

image->red[0][0] = 1;
 
I see 2 errors in your code (well... 1, but you make it twice). Your pointers are uninitialized. When you declare "image", you should do:

rgbimage* image;

and then

// alocate the memory image will use (you can change the dimensions to suit your needs
Code:
image = new rbimage;
image->red = new int*[10];
for( i = 0; i < 10; i++ )
{
    image->red[i] = new int[10];
}

DO NOT FORGET TO USE delete AND delete[]! See threads
thread116-320826
and
Thread116-107726

for more info about multidimensionnal dynamic arrays.

Good luck!

Vincent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top