Title: comp104 notes
1Summary 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)
2Static 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
3classes
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!
4Dynamic classes
class B public B(sometype) //
constructors B(const B b) // copy
constructor B operator(const B) // copy
assignment B() //
destructor private int px
5BB() 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
6Automatic 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