Friday, 15 August 2014

arrays - C++ 2d Vector subscript out of range error -


Currently in my work, I have a method that declares 2D vector.

  vector & lt; Vector & lt; Test & gt; & Gt; Path (int x, int y) // path function {vector & lt; Vector & lt; Test & gt; & Gt; Maze Array (column, vector, & lt; test & gt; (line)); // for one object (int a = 0; a & lt; column; a ++) {for (int b = 0; b & lt; line; b ++) {majear [b] [a] STX (B); MazeArray [b] [a] .setY (a); }}}  

For example, when I tried to run the function, path (10,10).

Double work for the loop completely without any errors, but if I change the path for example, path (11,10) or path (11,13) or number which both (Int x and y), the error outside the category vector subscript will be present.

Why is that so? Can anyone help me on this? Is there a way to decide whether any price I accept? Thank you.

Loop in function

  vector & lt; Vector & lt; Test & gt; & Gt; Path (int x, int y) // path function {vector & lt; Vector & lt; Test & gt; & Gt; Maze Array (column, vector, & lt; test & gt; (line)); // for one object (int a = 0; a & lt; column; a ++) {for (int b = 0; b & lt; line; b ++) {majear [b] [a] STX (B); MazeArray [b] [a] .setY (a); }}}  

Incorrectly you have to exchange b and one index. {For (int b = 0; b & lt; row; b ++) {mazeArray [a] [b] should be

  (int a = 0; a & lt; Column; a ++) .setX (b); MazeArray [A] [B] .setY (a); }}}  

The meaning of the function parameter is unclear because it is not used. :)


No comments:

Post a Comment