我无法理解重载类的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