advanced classes and dynamic memory allocation data structures and algorithms cs 244 brent m....
TRANSCRIPT
PowerPoint Presentation
Advanced Classesand Dynamic Memory AllocationData Structures and AlgorithmsCS 244Brent M. Dingle, Ph.D.Department of Mathematics, Statistics, and Computer ScienceUniversity of Wisconsin Stout
Based on the book: Data Structures and Algorithms in C++ (Goodrich, Tamassia, Mount)Some content derived/taken from: http://www.cplusplus.com/ and some from C++ Through Game Programming (Dawson)
Connect Speakersfor this PresentationRoughly 90 minutes, with no skippingLater slides may need updated/improved1Things to NoteHomework 4 is Due Soon
Homework 5 is Posted on D2LDo NOT delay in starting it
Do not forget to look at the Meta-Info filesFrom Last TimeReviewed C++ ClassesEnumerated TypesOperator Overloading
References in C++
Pointers in C++ Pointers Program: in-class activityPointers as parameters to functions (Swap)Returning Ptrs from function (on your own - InventoryPtr)Arrays as pointersTic-Tac-Toe via pointers
For TodaySome of this has been seen alreadyWe will add a few more details today
Advanced ClassesUse friend functionsOverload operators
Dynamic MemoryAllocate and free memoryAvoid memory leaksMarker SlideAny General Questions ?
Next upMaking friends and overloading functions in your classes (FriendCritter)Dynamically Allocating MemoryMemory LeaksUsing new and delete [] with arraysClasses and Dynamic MemoryAllocation SummaryMore on ClassesConstructors and Destructors with Dynamic MemoryOverloading Constructors (copy constructor)Overloading the Assignment OperatorGraded In-Class Activity: HeapDataMemberFriend Functions and Overloading OperatorsFriend functions have complete access to any member data of a class
Operator Overloading allows you to define new meanings for built-in operators as they relate to objects of your own classIn-Class Activity: FriendCritterDownload, compile, and run the FriendCritter example on D2L
Discussion on this will follow shortly7Looking at FriendCritter//Friend Critter//Demonstrates friend functions and operator overloading
#include #include
using namespace std;
class Critter{ //make the following global functions friends of the Critter class friend void Peek(const Critter& aCritter); friend ostream& operator