Hallöchen,
arbeite mich gerade in C++ ein und habe da Probleme mit dem überladen des
<<-Operators für std::cout
Hier Auszüge aus dem Quellcode:
"ratio.h"
8< schnipp
// Ausgabe einer rationalen Zahl
std::ostream& operator<<(std::ostream&, const rational&);
8< schapp
"ratio.cpp"
8< schnipp
std::ostream& operator<<(std::ostream& out, const rational& r) {
out << r.zaehler << '/' << r.nenner;
return out;
}
8< schnapp
"main.cpp"
8< schnipp
// Funktion zum einfachen Testen inkl Ausgabe
void druckeTestfall(const rational &a, const rational &b) {
rational erg; // Ergebnis
std::cout << "\na = " << a;
std::cout << "\nb = " << b << std::endl;
erg += a;
std::cout << "+ = " << erg << std::endl;
erg = a + b;
}
int main() {
rational a,b;
std::cout << " Test der Eingabe\n";
std::cout << "Rationale Zahl a eingeben\n";
std::cin >> a;
std::cout << "Rationale Zahl b eingeben\n";
std::cin >> b;
druckeTestfall(a,b);
}
8< schnapp
Nun erhalte ich beim Compilieren folgende Meldung:
paumit@dg4:~/Documents/cppbuch/k09/ratio>g++ -Wall -o main main.cpp
/tmp/ccbthCqf.o(.text+0x32): In function `druckeTestfall(rational const&,
rational const&)':
: undefined reference to `operator<<(std::basic_ostream