hey, i have overridden operator<< and when i’m trying to use it in a print method (const) i’m getting an error :
the overriden operator :
ostream& operator <<(ostream& os, Date& toPrint)
{
return os << toPrint.GetDay() << "/" << toPrint.GetMonth() << "/" << toPrint.GetYear();
}
where i’m trying to use it :
void TreatmentHistory::TreatmentHistoryPrint() const
{
cout << m_treatmentDate << "\n" << endl;
}
You are using your
operator<<in aconstmember function, thusm_treatmentDateisconst(unless declaredmutable). You need to fix youroperator<<to takeconstarguments:Note that for this to work
GetDay(),GetMonth()andGetYear()have to beconstmember functions as well.