I am working on implementing a balanced tree in C ++, but the requirement of the assignment is that I have to use template classes. At first I thought about how to do this with ints, and then convert it to templates, but for the test code that is provided to us, templates are used by default.
When I compile my code with g ++ class.h test.cxx -Wall -g -O0, everything works fine until I go to gdb where it will not be part of the template implementation. My template implementation file is included at the end of the header file, and gdb will let me set breakpoints in it, but it never comes into function. I used gdb through emacs, but it did not work directly in gdb. I would expect this step to switch to the template file when GDB gets to the function that is implanted, but instead it tells me that the line it thinks should go to does not actually exist. Here is a typical session:
(gdb) break set.template:7 Breakpoint 3 at 0x400c46: file set.template, line 7. (gdb) run The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /home/students/jeffris/csci2270/btree/debug Breakpoint 1, main () at debug.cxx:9 (gdb) step Breakpoint 3, set (this=0x7fffffffe550) at set.template:7 Line number 7 out of range; set.template has 1 lines. (gdb) set() Line number 8 out of range; set.template has 1 lines. (gdb) Line number 9 out of range; set.template has 1 lines. (gdb) Line number 10 out of range; set.template has 1 lines. (gdb) main () at debug.cxx:10 (gdb) main_savitch_11::set<int>::empty (this=0x7fffffffe550) at set.template:70 Line number 70 out of range; set.template has 1 lines. (gdb) empty Line number 71 out of range; set.template has 1 lines. (gdb) Line number 72 out of range; set.template has 1 lines. (gdb)
I saw several posts on the Internet about other people who faced similar problems, but the threads all died without permission. I tried several ways to compile the code, including in separate parts, and then put it all together, but not in cubes. Everyone else in my class has the same problem, but he is pleased to use cout instructions for debugging, which is very slow to debug 10 functions that call each other. Has anyone else experienced this and found a solution?
source share