[問題] 只能一個參數?
小弟有各 CLASS 但是在重載<<時
一直有個錯誤
std::ostream如下& Complex::operator<<(std::ostream&, Complex)’
must take exactly one argument
可是一般重載<<時 不都是設一個OSTREAM嗎?
還是這是g++的限制呢?
謝謝大家指教
#include<iostream>
class Complex
{
private:
double re, im;
public:
Complex(double r, double i): re(r), im(i) {}
Complex operator+(const Complex&);
std::ostream& operator<<(std::ostream& out, const Complex x);
};
Complex Complex::operator+(const Complex& a)
{
Complex c(a.re+re,a.im+im);
return c;
}
std::ostream& Complex::operator<<(std::ostream& out, const Complex x)
{
out << x.re << " " << x.im;
return out;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.60.0.221
推
04/13 21:47, , 1F
04/13 21:47, 1F
推
04/13 21:48, , 2F
04/13 21:48, 2F
→
04/13 22:55, , 3F
04/13 22:55, 3F
推
04/14 00:55, , 4F
04/14 00:55, 4F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章