Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
C subset
"Better C" enhancements (e.g. referring to structs etc. with tags)
classes
data abstraction (enhancing classes with operator overloading)
derived classes (inheritance, polymorphism, dynamic binding)
templates and exceptions (not really OOP related)
standard C++ libraries
method
encapsulation
class
a description of the data structures, methods and default values for a type
of object
An object is referred to as an instance of a class to indicate that its
behaviors and interface are determined by that class.
inheritance
data
abstraction
struct Rect {
int m_x, m_y, m_width, m_height;
Rect(int x, int y, int width, int height):
m_x(x), m_y(y), m_width(width), m_height(height) { }
};
class UIComp { // user-interface component (abstract)
char *id;
Rect dim;
// ...
public:
UIComp(const char *name);
const char *name() const { return id; }
virtual void redraw() const = 0;
virtual void resize(const Rect &) = 0;
// ...
};
class UICompMgr :
UIComp ** list;
int size;
// ...
public:
UICompMgr(const
void add(UIComp
// ...
};
char *name);
*);
public:
enum Policy { Matrix, PackRow, PackCol };
UIRowCol(const char *name, Policy pol = Matrix);
Policy InqPolicy() const { return policy; }
void resize(Rect &);
// ...
};
class UIPrim : public UIComp { ... }; // non-manager components
class UIValuator : public UIPrim {
// component to retrieve value from user
int value;
...
};
class UIBar : public UIValuator {
// value between max and min
int max, min;
};
class UIDial : public UIValuator {
// wrap around values
int scale;
};
UIRowCol panel("panel");
UIComp *comp = &panel; // in C:
comp's
"static" type is UIComp *. This is the class of the "accessed sub-object". This type
never changes, it's static. comp's "dynamic" type is UIRowCol * at this point. This is the
class of the "complete object" a sub-object of which has been accessed. Also called the
"most derived class" for the object. This type will change depending on what comp points
to.
cout << "This component's name is " << comp->name() << '\n';
// calls UIComp::name() - binding made at compile time
comp->resize(Rect(10, 10, 300, 400));
// calls UIRowCol::resize() - binding made at run time
// using info stored with object (typically ptr to table of func ptrs)
A left_turn_light is a light.
2. is_part_of (or hasa - reversed sense but same idea) - contained by another object -containing object has exclusive use -- actually just a stronger case of (3) below
Example:
class Car { Wheel wheels[4]; };
C's future is as a portable "universal" assembler, a back end for code generators.
While any C++ compiler should be able to compile a C program successfully with minor
changes, several aspects of C programming are discarded in the transition to C++: new
facilities are supplied for I/O, memory allocation and error handling; macros and pointer
casts become obsolete for the most part.
type safe situations in which an object is used in a way which is incompatible with its
type are quickly detected