1 / 12

Lab 2 main issues

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

nealparker
Download Presentation

Lab 2 main issues

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 CS-321Dr. 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 CS-321Dr. 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() CS-321Dr. 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 CS-321Dr. 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! CS-321Dr. Mark L. Hornick

  6. Lab 2 main issues • Assignment operator=… • No check for self-assignment • Assignment should replace previous, not append CS-321Dr. 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; } CS-321Dr. Mark L. Hornick

  8. Debugging your programs in Linux • What causes segmentation faults? • How do you find the source of a segmentation fault? CS-321Dr. 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) CS-321Dr. Mark L. Hornick

  10. 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

  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-2.1.13/ -lefence CS-321Dr. 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 CS-321Dr. Mark L. Hornick

More Related