ofstream& operator<<(ostream &outStream, const EventClass &eventObject)
{
outStream << eventObject.getEventName() << " event at "
<< eventObject.getEventTime() << endl;
return(outStream);
}
I believe this snippet is sufficient to analyze the error.
When I compile my code I get the following errors:
error: passing ‘const EventClass’ as ‘this’ argument of ‘std::string EventClass::getEventName()’ discards qualifiers [-fpermissive]
outStream << eventObject.getEventName() << " event at "error: passing ‘const EventClass’ as ‘this’ argument of ‘int EventClass::getEventTime()’ discards qualifiers [-fpermissive]
<< eventObject.getEventTime() << endl;error: invalid initialization of reference of type ‘std::ofstream& {aka std::basic_ofstream&}’ from expression of type ‘std::ostream {aka std::basic_ostream}’
return(outStream);
Any ideas how to solve these errors?
getEventName
method marked asconst
? – The Dark