FOUT: ‘Ostream’ Noemt geen type

Ik ben overbelasting van het & lt; & lt; en & GT; & GT; Operator in C++, maar het kan niet compileren.

Het foutbericht is: “FOUT: ‘Ostream’ Noemt geen type”
Waarom heb ik deze fout? Hoe het te repareren?

#ifndef COMPLEX_H
#define COMPLEX_H
#include <cstdlib> //exit
#include <istream>
#include <ostream>
class Complex{
    public:
    Complex(void);
    Complex(double a, double b);
    Complex(double a);
    double real() const{ 
        return a;
    }
    double imag() const{
        return b;
    }
    friend ostream& operator<<(ostream& out,const Complex& c);
    friend istream& operator>>(istream& in, Complex& c);
    private:
    double a;
    double b;
};
ostream& operator<<(ostream& out,const Complex& c){
    double a=c.real() , b = c.imag();
    out << a << "+" << b<<"i";
    return out;
}
istream& operator>>(istream& in, Complex& c){
    in >> c.a>> c.b;
    return in;
}
#endif

Antwoord 1, Autoriteit 100%

Gebruik std::ostreamen std::istreamOveral.

ostreamen istreamzijn in NameSpace std


Antwoord 2, Autoriteit 15%

Gekwalificeerde namen van de VS voor typen gedefinieerd in NameSpace STD

friend std::ostream& operator<<(std::ostream& out,const Complex& c);

Het zou ook beter zijn om <iostream>te opnemen in plaats van twee afzonderlijke headers <istream>EN <ostream>


Antwoord 3, Autoriteit 12%

u bent vergeten

toe te voegen

using namespace std;

Other episodes