c++ - What does access violation mean? -
i'm new c++ , not understand why getting error "access violation reading location". here code:
gdiscreen(); int startx = 1823 - minusx; int starty = 915 - minusy; (int = startx; < startx + 61; i++) { (int j = starty; j < starty + 70; j++) { color pixelcolor; bitmap->getpixel(i, j, &pixelcolor); cout << pixelcolor.getvalue() << " "; } cout << endl; }
gdiscreen() can found here: http://forums.codeguru.com/showthread.php?476912-gdi-screenshot-save-to-jpg
please help!!
access violation or segmentation fault means program tried access memory not reserved in scope.
have few examples how achieve this:
leaving bounds of array:
int arr[10]; for(unsigned char i=0; i<=10; i++) //will throw error @ i=10 arr[i]=0;
note: in code above, use unsigned char
iterate. char 1 byte, unsigned char
0-255. larger numbers, may need unsigned short
(2 bytes) or unsigned int
(4 bytes).
accidentally calculating pointer instead of integer
int ah = 10; int *pointer = &ah; //for reason, need pointer pointer++; //we should've written this: (*pointer)++ iterate value, not pointer std::cout<<"my number:"<<*pointer<<'\n'; //error - accessing ints address+1
i intentionally started broad explanation. wanted know access violation @ first place. in particular code, i'm sure messed i
, j
boundaries. std::cout
debug.
Comments
Post a Comment