我無法理解重載類的ostream方法時收到的錯誤。在class.cpp瞭解ostream過載
ostream& operator<<(ostream& out, const dateType& d)
{
out << d.getYear() << "-" << d.getMonth() << "-" << d.getDay()
return out;
}
代碼我知道所有三個干將的工作,在我main.cpp中對其進行測試。
然而,當我運行類似:
cout << d1 << endl:
我得到這個錯誤:
‘std::ostream& dateType::operator<<(std::ostream&, dateType&)’ must take exactly one argument
ostream& operator<<(ostream&, dateType&);
我寫了這樣一個ostream代碼,另一個程序工作正常。那麼,爲什麼我在這裏得到錯誤?
您可能已將其聲明爲成員。它應該是非會員。 – juanchopanza 2014-10-31 11:20:34