Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;错误:如何解决malloc:**对象错误。。。未分配要释放的指针_C++_C_Pointers_Memory_Malloc - Fatal编程技术网

C++ C++;错误:如何解决malloc:**对象错误。。。未分配要释放的指针

C++ C++;错误:如何解决malloc:**对象错误。。。未分配要释放的指针,c++,c,pointers,memory,malloc,C++,C,Pointers,Memory,Malloc,为什么编译后会出现此错误: Program1(49296,0x7fff74b72000)malloc:**对象0x7f9222500040的错误:未分配要释放的指针 有办法解决吗?我只在递归时得到它,但如果我去掉这行: if(counter == G.nameSet.size()) { explore(G, *adjPtr); } …然后就行了 void explore(Graph & G, Node & foo) { G.nameSet.insert(foo.na

为什么编译后会出现此错误:

Program1(49296,0x7fff74b72000)malloc:**对象0x7f9222500040的错误:未分配要释放的指针

有办法解决吗?我只在递归时得到它,但如果我去掉这行:

if(counter == G.nameSet.size())
{  
  explore(G, *adjPtr);
}
…然后就行了

void explore(Graph & G, Node & foo)
{
  G.nameSet.insert(foo.name());
  set <string> tempNameSet;

  list <Node> adjacentList = G.getAdjNodes(foo); 

  int y = adjacentList.size();
  list<Node>::iterator adjPtr = adjacentList.begin();

  for(int i=0; i < y;  i++ )
  {
tempNameSet = G.nameSet;

set<string>::iterator nSetPtr = G.nameSet.begin();
int counter = 0;
for (int j = 0; j < G.nameSet.size(); j++)
{ 
  if(*nSetPtr != adjPtr->name())
    counter++; 

  if(tempNameSet.size() > 1)
    nSetPtr  = tempNameSet.erase(nSetPtr);
}

if(counter == G.nameSet.size())
{  
  explore(G, *adjPtr);  //even when I plug in foo instead of *adjPtr, i get the same error
}

if(adjacentList.size() > 1)
  adjPtr  = adjacentList.erase(adjPtr);

  }
}
void explore(图形&G、节点&foo)
{
G.nameSet.insert(foo.name());
设置临时名称集;
list-adjacentList=G.getadjacenodes(foo);
int y=邻接列表.size();
列表::迭代器adjPtr=adjacentList.begin();
for(int i=0;iname())
计数器++;
if(tempneset.size()>1)
nSetPtr=临时名称集擦除(nSetPtr);
}
if(计数器==G.nameSet.size())
{  
explore(G,*adjPtr);//即使我插入foo而不是*adjPtr,我也会得到同样的错误
}
如果(adjacentList.size()>1)
adjPtr=邻接列表。擦除(adjPtr);
}
}

这很难,因为该函数不是直接免费调用的。据猜测,它在擦除(adjPtr)中崩溃。要验证这种情况,请在调用之前和之后输入诊断打印F,在调用之间应发生崩溃。adjPtr可能会变为空,这会导致擦除失败,但很难确定逻辑错误的确切位置。

您之所以会出现此错误,是因为代码中存在错误。遗憾的是,您的问题未能满足提供;因此,asnwer的可能性极低。您需要编辑您的问题,并用简洁、紧凑的替换当前包含的随机选择的代码块。好的,Sam,刚才做的
nSetPtr
用迭代器初始化为
G.nameSet
,但您将其传递给
tempNameSet.erase
。因此,您的程序表现出未定义的行为。仍然有许多对未知代码的函数调用。请研究如何对代码执行调试,然后返回并报告消息显示的确切行/修复标题。你不能“管理”这个。你解决了导致它的问题。你不应该在C++程序中调用<代码> MalCube()/<代码>或<代码> For()。