-
April 9th, 2012, 06:55 AM
#1
help looping through a vector of vectors
Figured it out, nevermind!
Ellay K.
Last edited by ekhule; April 9th, 2012 at 07:19 AM.
-
April 9th, 2012, 07:15 AM
#2
Re: help looping through a vector of vectors
Originally Posted by ekhule
What am I doing wrong?
You're reading an unsigned char out of the inner vector, then cast that to a pointer to an uint8_t, which is nonsense, because the unsigened char from the vector certainly does not contain the memory address of anything, and then try to read from that non-address, which triggers the exception. Simply remove the entire cast, including both the * and you'll be fine:
Code:
int temp = data[i][j];
The cast is completely unnecessary here anyway, since the conversion from unsigned char to int is performed completely seamlessly by the C+ compiler. You'll probably not even get a compiler warning about converting between types of different signdness.
This is a perfect demonstration of the fact that casts in general are dangerous and should be avoided if possible. And the reinterpret cast is particularly dangerous.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|