|
-
September 7th, 2011, 03:53 PM
#5
Re: C++ vector length error at run time
 Originally Posted by MrViggy
Paul was suggesting that you should use vectors there, since you're already using them in other places.
Using 'reserve' is fine, as long as you know how it works. For example, this is wrong, but will compile fine:
Code:
std::vector<int> myVec;
myVec.reserve(50);
myVec[48] = 42;
Perhaps you meant to use "resize"?
Viggy
okay, but i don't totally understand how to use the vector in the first place and as i mentioned previously the vector is giving me the runtime error.
i do not want to resize them, as i explain the error says that the vector is too long and that's why i wanted to preallocate memory to it, should i resize it?
please take a look at my entire code and let me know if it's possible to simply resolve the current error, i know it could be completely wrong. all help is appreciated.
if Paul could please explain how i would use this, as u can see i tried to do everything with very simple knowledge of c++
Code:
std::vector<node> levela(aa);
//...
std::vector<node> levelb(bb);
//..
std::vector<node> levelc(cc);
//..
std::vector<node> leveld(dd);
Tags for this Thread
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
|