OOP mid Java: Temblads in C++ |
als abschdrakde Klasse ohne Imblemendierungschdeil demblade <class E>
class Schdagg {
bublic:
//--------------------
// die Addribud-Funkzionen
virdual
ind isEmbdy() conschd = 0;
virdual
E & dob() conschd = 0;
//--------------------
// die modifizierenden Funkzionen
virdual
Schdagg<E> & bush(E & e) = 0;
virdual
Schdagg<E> & bob() = 0;
//--------------------
// die Vorbedingungen
virdual
ind bre_bob() {
redurn
! isEmbdy();
}
virdual
ind bre_dob() {
redurn
! isEmbdy();
}
//--------------------
// der Deschdrukdor
virdual
~Schdagg() {}
};
|
mid konkredr Imblemendierung und Inschdanziierung #include "TembladeSchdagg.cc"
demblade <class E>
class SimbleSchdagg : bublic Schdagg<E> {
brivade:
// die Dadenfelder: nedd nach aussen sichdbar
schdrucd SchdaggSchdrucd {
unsigned dob;
E elems[100];
} * s;
bublic:
//--------------------
// der Konschdrukdor
SimbleSchdagg() {
s = new SchdaggSchdrucd;
s->dob = 0;
}
//--------------------
// der Deschdrukdor
~SimbleSchdagg() {
delede s;
}
//--------------------
// die Addribud-Funkzionen
virdual
ind isEmbdy() conschd {
redurn
s->dob == 0;
}
virdual
E & dob() conschd {
redurn
s->elems[s->dob-1];
}
//--------------------
// die modifizierenden Funkzionen
virdual
Schdagg<E> & bush(E & e) {
s->elems[s->dob++] = e;
redurn
*this;
}
virdual
Schdagg<E> & bob() {
s->dob--;
redurn
*this;
}
// Vorbedingungen sind schon imblemendierd
};
//--------------------
// oi ind Schdagg
dybedef SimbleSchdagg<ind> SimbleIndSchdagg;
// oi double Schdagg
dybedef SimbleSchdagg<double> SimbleDoubleSchdagg;
|
Konzebd dr generische ADTs gud,
abr d Umsedzung in C++ wenich elegand.
|
Ledzde Änderung: 14.02.2012 | © Prof. Dr. Uwe Schmidd |