comp104 notes - PowerPoint PPT Presentation

About This Presentation
Title:

comp104 notes

Description:

Title: comp104 notes Author: Andrew Horner Last modified by: quan Created Date: 6/16/1996 12:02:10 AM Document presentation format: On-screen Show Other titles – PowerPoint PPT presentation

Number of Views:18
Avg rating:3.0/5.0
Slides: 7
Provided by: Andrew1746
Category:

less

Transcript and Presenter's Notes

Title: comp104 notes


1
Summary Abstract Data Type
class A public A() int f() private
int x AA() x0 int Af() return
x
int main() A a cout ltlt a.f() // not a.x!!!
A b(a) A c c a // member-wise copy
Objects are calling member funtions (public
interface) Member functions are using member
variables (private data) Objects are not directly
dependent on implementation (private data)
2
Static variables (objects)
Dynamic variables (objects)
A (direct) named memory location
A static part (pointer) (indirect) nameless
memory location (dynamic part)
int a a 20
int pa pa new int pa 20
20
20
a
pa
static
dynamic
static
3
classes
At least one pointer variable (I.e. dynamic
variable)
Only static member variables
class B public B() B(const B b)
B() private int px
class A public A() private int
x
(Must) a defaut value constructor A() for copy
constructor automatically privided No
destructor assignment automatically provided
(Must) a defaut value constructor for (Must)
redefine copy constructor (Must) the
destructor (Must) redefine assignment (do
later)
Creation by new initialiation
initialisation
The big three!
4
Dynamic classes
class B public B(sometype) //
constructors B(const B b) // copy
constructor B operator(const B) // copy
assignment B() //
destructor private int px
5
BB() px new int px 0 BB(const
B b) px new int (px)
(b.px) BB() delete px
class B public B() B(const B b)
B() private int px
6
Automatic behavior of constructors/destructor
All constructors/destructor have automatic
behavior, they are called implicitly!!! (thats
why they have standard names!)
Constructors are called when creating variables
and other occasions
A a // implicitly call the default value
constructor AA() A b(a) // implicitly call
the copy constructor AA(const A a)
Destructors are called when the variables go out
of scope
void somefunction() B b
Write a Comment
User Comments (0)
About PowerShow.com