120 likes | 138 Views
Lab 2 main issues. Point and line classes should NOT have their own protected “type” attributes these hide the parent (shape) classes attribute with the same name. Lab 2 main issues. Point and line operator=() shouldn’t copy serial number attribute Serial numbers should be unique
E N D
Lab 2 main issues • Point and line classes should NOT have their own protected “type” attributes • these hide the parent (shape) classes attribute with the same name CS-321Dr. Mark L. Hornick
Lab 2 main issues • Point and line operator=() shouldn’t copy serial number attribute • Serial numbers should be unique • Point and line copy constructor doesn’t copy “type” attribute • Base class copy constructor not automatically called CS-321Dr. Mark L. Hornick
Lab 2 main issues • Image destructor does not call delete the shapes in the collection or clear the vector/list • memory leaks • Just call Erase() CS-321Dr. Mark L. Hornick
Lab 2 main issues • Clear() -ing the shape collection in image::operator=, Erase(), or destructor, but not deleting the objects • memory leaks CS-321Dr. Mark L. Hornick
Lab 2 main issues • Shallow copies • Image copy constructor • Image::operator=() • Just copying pointers to shapes results in multiple references to the same shape! CS-321Dr. Mark L. Hornick
Lab 2 main issues • Assignment operator=… • No check for self-assignment • Assignment should replace previous, not append CS-321Dr. Mark L. Hornick
Don’t assign over yourself! operator= Example Employee& Employee::operator=(const Employee& rhs) { if (this != &rhs) { age = rhs.age; …; } return *this; } CS-321Dr. Mark L. Hornick
Debugging your programs in Linux • What causes segmentation faults? • How do you find the source of a segmentation fault? CS-321Dr. Mark L. Hornick
Steps to solving segmentation faults • Modify your .pro file to build a debug version of your program • …and link the Electric Fence shared library into your program during the link step • Run your program from within the GNU debugger (gdb) CS-321Dr. Mark L. Hornick
Electric FenceA runtime head memory monitor • Download Electric Fence (free) http://perens.com/FreeSoftware/ElectricFence/ • Unzip to someplace on you filesystem • Remake the project • make clean • make • This builds the shared library libefence.so CS-321Dr. Mark L. Hornick
Add the following lines to your .pro file … #CONFIG += qt warn_on release thread #original CONFIG += qt warn_on debug thread … #add library to linker’s search path unix:LIBS += =L/home/hornick/cs321/efence/electric-fence-2.1.13/ -lefence CS-321Dr. Mark L. Hornick
Debugging with gdb • Use Adept Package Manager to install gdb • Run gdb – get gdb prompt • file <file> - loads your executable file into gdb • run - starts your program • bt - backtrace – a stack dump with line numbers • quit - exit gdb • Fix problem located by gdb/electric fence CS-321Dr. Mark L. Hornick