-1

i'm making a simple snake game in c++. it compiles, but won't run. i'm using netbeans on a mac, and i've never had a problem like this before, so i assume it's a problem with my code:

#include <vector>
std::vector<std::vector<int> > snake;//the snake
int main(){
    snake[0][0]=0;
}

i think it might be a problem with the 2d vector.

4

1 回答 1

5

snake[0][0] = 0具有未定义的行为,因为您试图分配给不存在的向量元素。

也就是说 -snake.size() == 0因此访问第一个元素snake[0]不是有效的操作。

于 2012-03-24T00:29:06.663 回答