Titel sagt alles. Ich überlastete den Operator < <, wie jeder im Internet sagte, aber ich habe immer noch diesen dummen Fehler für einen ungültigen Betreiber. Was habe ich falsch gemacht? Hier ist mein Code:Kann `cout` nicht mit einer Klasse verwenden, selbst wenn ich` operator << überladen habe
#include <iostream>
#include <cstdio>
using namespace std;
class Calc {
private:
union _Print_Datatypes {
int I;
double D;
string S;
char C;
};
public:
int i;
void Sum(long double _a, long double _b) {
return _a + _b;
}
void Sub(long double _a, long double _b) {
return _a - _b;
}
void Div(long double _a, long double _b) {
return _a/_b;
}
void Mult(long double _a, long double _b) {
return _a * _b;
}
};
std::ostream &operator<<(std::ostream &os, Calc const &m) {
return os << m.i;
}
int main() {
Calc _calc;
cout << _calc.Sum(2,2);
}
Was ist der genaue Fehler, den Sie bekommen? – NathanOliver
Was ist der Rückgabetyp der Summenelementfunktion ...? ;) –
... \ main.cpp | 42 | Fehler: keine Übereinstimmung für 'Operator <<' (Operandentypen sind 'std :: ostream {aka std :: basic_ostream}' und 'void') | –