简体   繁体   English

push_back std :: pair转换为std :: vector错误

[英]push_back std::pair into std::vector error

When I try to add a pair to a vector I get this error: 当我尝试将一对添加到向量时,出现此错误:

table: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
Aborted

Here is the method: 方法如下:

std::vector<std::pair <int, int> > AI::genPosNormal(int p, int dice)
{
  std::vector<std::pair <int, int> > pos;
  std::pair<int, int> step;

  for(int i = p; i < 25-dice; i++){
    if(board[BLACK][i] > 0 && board[WHITE][i+dice] < 2){
      step.first = i;
      step.second = dice;
      pos.push_back(step);
    }
  }
  return pos;
}

A little to late. 有点晚了。 But I found using .reserve() in std::vector of std::pair resolves the issue. 但是我发现在std :: pair的std :: vector中使用.reserve()可以解决问题。 I still have to figure out why the error is caused but seems like there in an stl_uninitialized.h which raises an error flag. 我仍然必须弄清楚为什么会导致错误,但似乎在stl_uninitialized.h中会引发错误标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM