ファーストをオーバーロードすることはできません私は取得していますエラーです:は、このすべての<<演算子
error: overloaded 'operator<<' must be a binary operator (has 3 parameters) std::ostream& operator<< (std::ostream& os, const Dcomplex& c);
と私は理由を理解していません。私はいくつかの他の質問を読んで、彼らはすべてconstを追加すると言ったが、私のために働いていない。
だからこれは私のヘッダファイルです:
#ifndef AUFGABE5_DCOMPLEX_H
#define AUFGABE5_DCOMPLEX_H
class Dcomplex {
private:
double re, im;
public:
Dcomplex(double r = 0, double i = 0);
Dcomplex(const Dcomplex& kopie);
~Dcomplex();
double abswert() const;
double winkel() const;
Dcomplex konjugiert() const;
Dcomplex kehrwert() const;
Dcomplex operator+(const Dcomplex& x)const;
Dcomplex operator-();
Dcomplex operator*(const Dcomplex& x)const;
Dcomplex operator-(const Dcomplex& x)const;
Dcomplex operator/(const Dcomplex& x)const;
Dcomplex& operator++();
Dcomplex& operator--();
const Dcomplex operator++(int);
const Dcomplex operator--(int);
std::ostream& operator<< (std::ostream& os, const Dcomplex& c);
std::istream& operator>> (std::istream& is, const Dcomplex& c);
bool operator>(const Dcomplex &x)const;
void print();
};
#endif //AUFGABE5_DCOMPLEX_H
私はそれが働いていない理由を任意のアイデアのために感謝しています。
編集:
std::istream& Dcomplex::operator>>(std::istream &is, const Dcomplex& c) {
double re,im;
std::cout << "Der Realteil betraegt?"; is >> re;
std::cout << "Der Imaginaerteil betraegt?"; is >> im;
Dcomplex(re,im);
return is;
}
'オペレータ<<' 'とオペレータ>>'非メンバ関数でなければなりません。 – songyuanyao