Download presentation
Presentation is loading. Please wait.
Published byStephen Houston Modified over 7 years ago
1
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 Fall 2004 CS-321 Dr. Mark L. Hornick
2
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 Fall 2004 CS-321 Dr. Mark L. Hornick
3
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() Fall 2004 CS-321 Dr. Mark L. Hornick
4
Lab 2 main issues Clear() -ing the shape collection in image::operator=, Erase(), or destructor, but not deleting the objects memory leaks Fall 2004 CS-321 Dr. Mark L. Hornick
5
Lab 2 main issues Shallow copies
Image copy constructor Image::operator=() Just copying pointers to shapes results in multiple references to the same shape! Fall 2004 CS-321 Dr. Mark L. Hornick
6
Lab 2 main issues Assignment operator=… No check for self-assignment
Assignment should replace previous, not append Fall 2004 CS-321 Dr. Mark L. Hornick
7
Don’t assign over yourself!
operator= Example Employee& Employee::operator=(const Employee& rhs) { if (this != &rhs) { age = rhs.age; …; } return *this; Don’t assign over yourself! Fall 2004 CS-321 Dr. Mark L. Hornick
8
Debugging your programs in Linux
What causes segmentation faults? How do you find the source of a segmentation fault? Fall 2004 CS-321 Dr. Mark L. Hornick
9
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) Fall 2004 CS-321 Dr. Mark L. Hornick
10
Electric Fence A runtime head memory monitor
Download Electric Fence (free) Unzip to someplace on you filesystem Remake the project make clean make This builds the shared library libefence.so Fall 2004 CS-321 Dr. Mark L. Hornick
11
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 / -lefence Fall 2004 CS-321 Dr. Mark L. Hornick
12
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 Fall 2004 CS-321 Dr. Mark L. Hornick
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.