Documente Academic
Documente Profesional
Documente Cultură
Semester organisation
End grade
Example:
Semester agenda
Sim ula
A da
Sm alltalk
M odula-2
Eiffel
O bjective-C
C+ +
O bjectPascal
M odula-3
O beron-2
Java
Pascal
High-level code
C++ source code
Compiler
Assembly-language
program
Assembler
Object code
Linker
Executable program
10
Library
11
argv[0]:
argv[1]:
argv[2]:
argc:
/home/mdm3/prg
arg1
arg2
3
12
Data members :
Member functions :
Attributes
Methods
Class declaration:
Describe the member functions and the data members of
the class
This is described in .h files (e.g. queue.h)
Class definition:
Contains the code that implements the member functions
This is described in .cpp files (e.g. queue.cpp)
Class declaration
13
Class TagName
{
// class body
};
Class body
Data members
Member functions
Example
14
class IntQueue
{
public:
int size( void );
int isEmpty( void );
int isFull( void );
void enqueue( int elem );
int serve( void );
protected:
int queueSize;
int front;
int rear;
int array[100];
};
15
Public member
Accessible from anywhere
Protected member
Behaves as public to a derived class
Behaves as private to the rest
#include "IntQueue.h
16
17
// safe
//unsafe
18
19
20
21
22
23
24
v1, int
v2){...}
25
26
27
28
29
Will be internally by the Compiler modified into a nonmember C function like this:
void Shift__Point(Point* this, int dx, int dy)
{
this->x += dx;
this->y += dy;
}
30
31
32
33
int TempFile::nrOfFiles = 0;
34
35
36
Examples
class X
{
public:
char* func(void) {return i;}; //inline by default
}
is the same as:
inline char* X::func(void)
{
return i;
}
37
38
class Vehicle
{
public:
Vehicle();
Vehicle(unsigned int wt);
unsigned int getWeight(void)
const;
void setWeight(unsigned int wt);
private:
unsigned int weight;
};
39
40
Private
Public
Protected
Public
inheritance
Private
member
Public
member
Protected
member
Private
inheritance
Private
member
Private
member
Private
member
Protected
inheritance
Private
member
Protected
member
Protected
member
41
42
43
44
The dynamic binding or late binding decides during runtime which classes operation will be executed
Virtual functions uses the dynamic binding
Without using virtual functions, no dynamic binding will be
performed, even if the pointers are cast to another class
type!
45
46
47
48