025
12.07.2003, 10:11 Uhr
~dj-union
Gast
|
Hi Leute!
Mittlerweile bin ich ein bissl weiter was das Programm betrifft... Soweit bin ich:
C++: |
#include <iostream> #include <string>
using namespace std;
typedef string Exception;
class Bruch { friend ostream &operator <<(ostream &, const Bruch &); friend Bruch operator *(int, const Bruch &);
public: Bruch(); Bruch(int, int) throw(Exception); Bruch(int);
protected: int x, y; };
Bruch::Bruch() : x(1), y(1) { return; };
Bruch::Bruch(int a, int b) throw(Exception) : x(a), y(b) { if (!b) throw "Division durch Null"; return; };
Bruch::Bruch(int a) : x(a), y(1) { return; };
ostream &operator <<(ostream &s, const Bruch &b) { s << b.x << "/" << b.y; return s; };
Bruch operator *(int i, const Bruch &b) { return Bruch(i * b.x, b.y); };
int main() { Bruch b1(3,4); Bruch b2;
b2 = 3 * b1; // 3/4 * 3 => Ausgabe: 9/4 cout << b2 << endl;
return 0; }
|
Aber leider funktioniert das nicht, weil der <<-Operator laut Compiler mehrdeutig ist...Hat jemand eine Idee worans liegt?
Mfg, dj-union |