【发布时间】:2014-12-16 04:54:36
【问题描述】:
我在 C++ 中重载了 > 运算符,但它无法编译。
错误信息是:“错误:‘ostream’没有命名类型” 为什么我会收到此错误?如何解决?
#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
【问题讨论】:
标签: c++ operator-overloading operators