c++ - terminate called after throwing an instance of 'std::invalid_argument' what(): dataItem already in tree Abort (core dumped) -
i'm getting error
terminate called after throwing instance of 'std::invalid_argument'what(): dataitem in tree abort (core dumped)
i've tried , can't think of possibly fix i'm assuming im storing tree when stored have no idea, appreciated below code - use 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 program"; exit(0); } mazerow row; ifstream infile(filein); char temp; unsigned int = 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 open file.."; } infile.close(); }
thank you
the error message indicates there exception being thrown not caught in code. being thrown in bintree
implementation, when try insert element key in?
you can use debugger break @ point exception thrown (in gdb catch throw
command) , can inspect why ended in situation.
Comments
Post a Comment