473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Incorrect vector subscript out of range

7
Hi all,
I'm working in visual studio 2010. I'm getting a "vector subscript out of range debug assertion check" -error, which I believe is incorrect.

I have created a minimal example:

Expand|Select|Wrap|Line Numbers
  1. int xsize = 4dVector.size();
  2. int ysize = 4dVector[x].size();
  3. int zsize = 4dVector[x][y].size();
  4. int nbelements = 4dVector[x][y][z].size();
  5.  
  6.     for (uint32_t i = 0; i < 4dVector[x][y][z].size(); i++) {        
  7.         Foo* foo = 4dVector[x][y][z][i];
  8.  
  9.         // do something
  10.     }
  11.  
The debugger shows the out-of-range message at line:
Foo* foo = 4dVector[x][y][z][i];

however, when inspecting all variables I find:

xsize = 20;
ysize = 20;
zsize = 20;
nbelements = 17;

x = 11;
y = 17;
z = 14;
i = 14;

I don't see the problem with that?
Also, every time I rerun the program in debugging mode, it breaks with different values in all variables, but always correct values. All help is much appreciated.
Feb 13 '12 #1

✓ answered by weaknessforcats

Are all of your vector eements initialized? The out-of-range error is common with usng uninitialized vectors.

Expand|Select|Wrap|Line Numbers
  1. vector<int> arr;
  2. arr[5] = 10;     //subscript out-of-range
  3. cout << arr[0];  //subscript out-of-range

2 2116
weaknessforcats
9,208 Expert Mod 8TB
Are all of your vector eements initialized? The out-of-range error is common with usng uninitialized vectors.

Expand|Select|Wrap|Line Numbers
  1. vector<int> arr;
  2. arr[5] = 10;     //subscript out-of-range
  3. cout << arr[0];  //subscript out-of-range
Feb 13 '12 #2
Sir G
7
Yes they all were initialized. I have found the problem though. It was a specific concurrency related issue of the program.

Thanks for all help though
Feb 13 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Steve | last post by:
Hi, I hope someone can help. I have a class called cField, and another class called cFieldList. cFieldList contains a std::vector of cFields called myvec I've overloaded the subscript...
5
by: Alexander Stippler | last post by:
Hello, I have got a list of indices stored as a stl::vector and a range given by two iterators, lets say . The values in this range are not ordered, but I have another range of values, lets say...
17
by: Michael Hopkins | last post by:
Hi all I want to create a std::vector that goes from 1 to n instead of 0 to n-1. The only change this will have is in loops and when the vector returns positions of elements etc. I am calling...
10
by: olson_ord | last post by:
Hi, I am not exactly new to C++, but I have never done operator overloading before. I have some old code that tries to implement a Shift Register - but I cannot seem to get it to work. Here's a...
6
by: josh | last post by:
Hi I've a dubt! when we have overloaded functions the compiler chooses the right being based on the argument lists...but when we have two subscript overloaded functions it resolves them being...
6
by: Andy | last post by:
Hi all, I started developing a little app on my Mac using XCode some month ago. The app is running fine on my mac like a sharm. Now I am nearly ready and yesterday I moved the whole source code...
2
by: flavourofbru | last post by:
Hi all, I am declaring 2 vectors as vector<int> abc; vector<int> xyz; i am passing the vector "xyz" as an argument to a function and the return value is stored in vector "abc". But it shows a...
2
by: subramanian100in | last post by:
For vector and deque, the 'at( )' member function throws out_of_range exception if the argument to the 'at( )' function is not in range. But the subscript operator does not throw this exception...
4
by: Han | last post by:
when I exe my project in vs.net2005,I got the error following: Debug Assertion Failed! Program:........ File:c:\program files\microsoft visual studio 8\vc\include\vector Line:756 ...
5
by: yogi_bear_79 | last post by:
Distant learning student. My lab is to write a function to perform the addition of large integers, with no limit to the number of digits. (Also have to do a subtraction, division, and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.