Professional Documents
Culture Documents
Week4 Classes
Week4 Classes
CS-2303
System Programming Concepts
(Slides include materials from The C Programming Language, 2nd edition, by Kernighan and Ritchie and
from C: How to Program, 5th and 6th editions, by Deitel and Deitel)
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
Reading
Deitel & Deitel, Chapter 19
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
Introduction to
Classes and Ob
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
CS-2303, C-Ter
Introduction to
7
Systems Programming:
Classes
m 2010
Classes and
Ob and Objects
ss
a
l
c
this main
f
o
ct
of
e
j
e
b
l
o
b
ria
an
a
g
v
n
i
c
lar
ati
Dec autom
n
I.e., allocated on The Stack
as a
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
Member function
parameter
Use the function
parameter as a
variable
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
10
Useful Tidbits
A string
Introduction to
Classes and Ob
11
Introduction to
Classes and Ob
12
Access-specifier private
Makes any member accessible only to
member functions of the class.
May be applied to data members and member
functions
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
13
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
14
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
15
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
16
Introduction to
Classes and Ob
17
Called automatically
When class object is declared as automatic variable
By new operator Compilers default simply calls constructors
of data members of the class.
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
18
Called automatically
When function exits scope of automatic class
object
default simply calls destructors of
By deleteCompilers
operator
data members of the class.
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
19
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
20
Constructor Example
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
21
Constructor Example
ject ry
b
o
ss
a
mo
l
e
c
m
s
thi cated
o
s
ed lly allo
e
n
ctor amica
u
r
t
Des ree dyn
f
can
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
22
Constructor Example
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
23
implemenations
Header files
Separate files in which class definitions are placed.
Allow compiler to recognize the classes when used elsewhere.
Generally have .h filename extensions
Driver file
A program used to test software (such as classes).
Contains a main function so it can be executed.
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
24
Introduction to
Classes and Ob
25
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
26
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
27
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
28
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
29
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
30
Summary
Introduced class definitions and objects
Public versus private access into class.
Introduction to
Classes and Ob
31
Questions?
Reading:
Deitel & Deitel, Chapter 19
CS-2303, C-Ter
m 2010
Introduction to
Classes and Ob
32