CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Posts
    166

    help looping through a vector of vectors

    Figured it out, nevermind!

    Ellay K.
    Last edited by ekhule; April 9th, 2012 at 07:19 AM.

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: help looping through a vector of vectors

    Quote Originally Posted by ekhule View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured