|
From: Ioannis V. <iv...@em...> - 2003-07-14 21:08:08
|
> -----Original Message----- > From: dev...@li...=20 > [mailto:dev...@li...] On Behalf=20 > Of Shane Bryldt > Sent: Monday, July 14, 2003 11:14 PM > To: Hossein Haeri > Cc: C++ > Subject: Re: [Dev-C++] STL Map question >=20 > When it breaks out into GDB in the crash,=20 > it leaves me at > a "map::find" statement, which, when I step into it, I find=20 > that the key (an > std::string) is valid, but the data portion, a pointer to an=20 > allocated User, > is somehow fubar'd, because if I try to print (no different=20 > than getting the > value of a variable in VC++ debugger) the pointer, GDB itself=20 > will indicate > that the program crashed while attempting to execute=20 > something by GDB. This > means that 1) the code crashes and drops me into the=20 > debugger, and 2) it is > in fact crashing because of the variable value, as executing=20 > the single > operation of printing the value causes an internal crash that=20 > GDB recovers > from, but ends execution of the program. This is happening because you use the library in an improper C style = way. Had the map contained objects instead of pointers you would find no = record when you used the find() and would get User(0) when accessed the key = using operator[]. Better use C++ as C++ and not as C. Quiz of the day: How do you write generic functions in C and how in C++? = :-) =20 > The problem I am seeing, I have never seen in all my time=20 > programming, and I > have a good 8 years background with C. Further issues with=20 > this, may result > in me reverting UserList to a true linked list=20 > implementation, instead of > STL, which could be the culprit even though I don't want to=20 > blame it.=20 !!! The problem is your programming approach, not the standard library! > Even > reverting temporarily to a C linked list may help me in=20 > travelling the list > in the debugger to find out where the problem is (like if=20 > it's the last or > first element, etc)... Short of testing my new changes, this=20 > will be the > next step, to revert to a very slow and simple linked list=20 > until I can track > down the problem. At least I have some direction, I=20 > appreciate the help > everyone has offered. The standard library provides a double linked list implementation, std::list. But your problem is that you code in C with classes, not C++! Ioannis Vranos =20 * Programming pages: http://www.noicys.freeurl.com * Alternative URL 1: http://run.to/noicys * Alternative URL 2: http://www.noicys.cjb.net |