0 c++ vector segmentation-fault push-back c++11
我的C++编译器表现得非常奇怪.
我的向量是全局定义的:
vector<int> values;
这不会导致任何错误:
void locate( int r, int s, bool newCheck, int from = 0 ){
static int A = 255;
static int U = 1;
static int D = 2;
static int R = 3;
static int L = 4;
values.push_back(0);
kocka *temp;
*temp = pole[r][s];    
values.push_back(1);
.........................
但是,这会导致错误分段错误:
void locate( int r, int s, bool newCheck, int from = 0 ){
static int A = 255;
static int U = 1;
static int D = 2;
static int R = 3;
static int L = 4;
//values.push_back(0);
kocka *temp;
*temp = pole[r][s];    
values.push_back(1);
...........................
用g ++编译-O2 -std = c ++ 11你知道它为什么会表现这种奇怪的方式吗?谢谢
temp永远不会被初始化为任何东西,所以当你通过它分配它时*temp = pole[r][s],你会得到未定义的行为,因为你试图写入一些随机的内存位置.初始化temp为合理的价值.
| 归档时间: | 
 | 
| 查看次数: | 578 次 | 
| 最近记录: |