Data Abstraction and Structures Using C++ Headington and Riley Chapter 7 Pointers and Dynamic Data

2/24/99


Click here to start


Table of Contents

Data Abstraction and Structures Using C++ Headington and Riley Chapter 7 Pointers and Dynamic Data

PPT Slide

PPT Slide

PointType class interface diagram

class PointType

PointType myPoint(4.0, 3.0); PointType yourPoint(1.0, 1.0);

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PointType myPoint(4.0, 3.0); myPoint.Write( );

PointType myPoint(4.0, 3.0); PointType yourPoint(1.0, 1.0); if (myPoint == yourPoint) { . . . }

PointType myPoint(4.0, 3.0); cout << myPoint.DistanceFromOrigin( );

PPT Slide

PointType myPoint(4.0, 3.0); PointType yourPoint(1.0, 1.0); cout << myPoint.DistanceFrom(yourPoint);

PPT Slide

PPT Slide

Recall that . . .

Addresses in Memory

Obtaining Memory Addresses

What is a pointer variable?

Using a pointer variable

Unary operator * is the indirection (deference) operator

Using the dereference operator

Another Example

Using a pointer to access the elements of a string

PPT Slide

PPT Slide

Some C++ pointer operations

Operator new Syntax

The NULL Pointer

3 Kinds of Program Data

Allocation of memory

Dynamically Allocated Data

Dynamically Allocated Data

Dynamically Allocated Data

Dynamically Allocated Data

Using operator delete

Dynamic Array Allocation

Dynamic Array Allocation

Operator delete Syntax

Dynamic Array Deallocation

What happens here?

Inaccessible Object

Making an Object Inaccessible

Memory Leak

A Dangling Pointer

Leaving a Dangling Pointer

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

PPT Slide

Why is a destructor needed?

class IntVec Destructor

What happens . . .

Passing a class object by value

Pass by value makes a shallow copy

Shallow Copy vs. Deep Copy

What’s the difference?

Making a deep copy

Suppose SomeFunc uses operator[]

beta[2] has changed

beta[2] has changed

As a result . . .

More about copy constructors

Copy Constructor

Classes with Data Member Pointers Need

PPT Slide

What about the assignment operator?

PPT Slide

C++ Operator Overloading Guides

Using overloaded binary operator=

Using overloaded binary operator+

class PointList from Roberge Lab 2

DOS Graphics Screen

Dragon depth 0

Dragon depth 1

Dragon depth 2

Dragon depth 3

Author: Sylvia Sorkin

Email: ssorkin@essex.cc.md.us

Home Page: http://www.essex.cc.md.us/Essex/People/ssorkin/index.html

Download presentation source