【发布时间】:2014-05-29 15:50:06
【问题描述】:
我收到了错误
在抛出一个实例后调用终止 'std::invalid_argument'what(): dataItem 已经在树 Abort (core 倾倒)
我已经尝试了所有方法,但我想不出任何可以解决此问题的方法 下面是我的代码 - 我也使用 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();
}
谢谢
【问题讨论】:
-
请使用调试器来识别导致错误的行(或至少是函数)
-
猜测是
bintree(无论 that 是什么)正在抛出异常,因为您尝试存储的某些值已经包含在其中。我们不知道bintree是什么,所以很难说。建议将try/catch包裹在points.insert(point)周围并记录冲突的值。这应该会给你一个线索。