獲取此錯誤,我很確定它在運營商< <功能。兩張照片都是公開的。錯誤C2248:'std :: basic_ios <_Elem,_Traits> :: basic_ios':無法訪問類中聲明的私人成員'std :: basic_ios <_Elem,_Traits>'
void CRational::print() const
{
print(cout);
}
void CRational::print(ostream & sout) const
{
if(m_denominator == 1)
cout << m_numerator;
else
cout << m_numerator << "/" << m_denominator;
}
ostream operator<<(ostream & sout,const CRational a)
{
a.print();
return sout;
}
CRational operator++() // prefix ++x
{
m_numerator += m_denominator;
return *this;
}
in main:
cout << "e before: " << e << ", \"cout << ++e\" : " << ++e << " after: " << e << endl;
感謝您的幫助。但是我遇到了一個新問題。當我使用這個函數時,數字以遞歸的方式向後打印。 – andrey 2011-02-28 04:54:58