我收到了错误
在抛出一个实例后终止调用 ' std :: invalid_argument' what():dataItem已经在树中止(核心) 倾倒)
我已经尝试了一切,我无法想到任何可能解决这个问题我假设我已经存储了树,但我不知道,任何帮助将不胜感激 下面是我的代码 - 我也使用bintree和binNode:
#include <iostream>
#include <string>
#include <ctype.h>
#include <fstream>
#include <stdlib.h>
#include "bintree.h"
#include "binnode.h"
using namespace std;
class mazePoint
{
private:
int x;
char pointType;
public:
void setPointMaze(char ch, int i)
{
pointType = ch;
x = i;
}
bool operator == (const mazePoint &other) const
{
return(this->x == other.x);
}
bool operator < (const mazePoint &other) const
{
return(this->x < other.x);
}
};
class mazeRow
{
private:
bintree<mazePoint> points;
int y;
public:
void setMazeRow(int rowNumber)
{
y = rowNumber;
}
bool operator==(const mazeRow &other) const
{
return(this->y < other.y);
}
bool operator<(const mazeRow &other) const
{
return(this->y < other.y);
}
void storePointMaze(char ch, int i)
{
mazePoint point;
point.setPointMaze(ch,i);
points.insert(point);
}
void incrementeRow()
{
y++;
}
};
void loadMaze(bintree<mazeRow> &maze, const char *filein, int argc);
int main (int argc, char* argv[])
{
unsigned int start = 0;
unsigned int finish = 0;
bintree<mazeRow> maze;
string filein;
loadMaze(maze, argv[1], argc);
return 0;
}
void loadMaze(bintree<mazeRow> &maze, const char *filein, int argc)
{
if ( argc < 2) {
cout << "Must supply 1 argument to this program";
exit(0);
}
mazeRow row;
ifstream infile(filein);
char temp;
unsigned int i = 0;
if (infile.is_open() && infile.good()) {
while (!infile.eof())
{
infile.get(temp);
i++;
row.storePointMaze(temp, i);
if(temp == '\n') ./
{
maze.insert(row);
row.incrementeRow();
}
}
}
else {
cout << "Failed to open file..";
}
infile.close();
}
谢谢
答案 0 :(得分:0)
错误消息表明引发的异常未在代码中捕获。当你试图插入一个其键已经存在的元素时,很可能会在binTree
实现中引发这种情况?
您可以使用调试器在抛出异常的位置中断(在gdb catch throw
中将是命令),然后您可以检查在这种情况下最终结束的原因。