Delegation, Objekt in Objekt
-
Wie behebt man diesen Fehler ???
#include <iostream> #include <string> #include <sstream> using namespace std; class Date { private : int _day, _month, _year; DateFormat *df; public : Date(int day,int month,int year) { _day = day; _month = month; _year = year; } string toString() { return df->format(this); } int getDay() { return _day; } int getMonth() { return _month; } int getYear() { return _year; } }; class DateFormat { public: virtual string format(Date *d) { ostringstream os; os << d->getDay() << "."; os << d->getMonth() << "."; os << d->getYear(); return os.str(); } }; int main() { Date d1(22,3,2000); cout << d1.toString(); getchar(); return 0; }Hiernochmal bei codepad : http://codepad.org/O1J9Vt0L
-
Das ist Murx. DateFormat will Date benutzen und vice versa. Mach das Design nochmals neu.