Thread: what is wrong with this line?

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    35

    Exclamation what is wrong with this line?

    Somewhere in my program, I have written the following line but it gives the error: vector subscript out of range and I can't figure out why.

    Code:
    if(!(list_of_queues[matches[k]->FirstQ]->empty()) && list_of_queues[(matches[k])->SecondQ]->empty())
    					{
    						...
    					}
    "list_of_queues" and "matches" are both vectors of pointers. "FirstQ" is an attribute of class "a" which is stored in vector "matches" as "a*".
    the interesting thing is that I have written the following code before this one and it gives no errors on that.

    Code:
    if(list_of_queues[matches[k]->FirstQ]->empty() && !(list_of_queues[matches[k]->SecondQ]->empty()))
    					{
    						...
    					}
    can somebody plz tell me what is wrong with that?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    That would suggest that one of your vector subscripts is out of range. If the first has problems and the second doesn't, that may come from the short-circuit evaluation of && -- if the left side comes out false, the right side just doesn't happen. So if, somehow, matches[k]->SecondQ is a bad subscript, you wouldn't necessarily get an error if the FirstQ check fails.

    You should run your program in a debugger and see what the values of k, FirstQ, and SecondQ are when this all happens.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 12-13-2010, 02:13 PM
  2. Error in printf line,,,what's wrong?
    By mft_ika in forum C Programming
    Replies: 9
    Last Post: 03-19-2010, 08:46 PM
  3. Replies: 1
    Last Post: 05-01-2003, 02:52 PM
  4. What's wrong in this line of code?
    By marCplusplus in forum C++ Programming
    Replies: 12
    Last Post: 12-12-2001, 09:16 AM
  5. command line program, something wrong in the argv
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 09-26-2001, 09:36 AM