Hi there, I’m wondering if it is possible to overload the ofLog "operator << " to print my custom objects. And if so, where do I need to place the overloaded functions in my code.
So far I have tried three ways, unsuccessfully.
// EngineEvent.h
class EngineEvent
{
public:
EngineEvent() {};
~EngineEvent() {};
// Attributes
map<string, string> s_data;
};
// EngineEvent.cpp
// First try
ofLog& operator<<(ofLog& log, const EngineEvent& obj)
{
for (pair<string, string> keyValue : obj.s_data) {
log << "{" << keyValue.first << ": " << keyValue.second << "}" << endl;
}
return log;
}
// Second try
ostream& operator<<(ostream& os, const EngineEvent& obj)
{
for (pair<string, string> keyValue : obj.s_data) {
os << "{" << keyValue.first << ": " << keyValue.second << "}" << endl;
}
return os;
}
// Desperate third try
ostringstream& operator<<(ostringstream& oss, const EngineEvent& obj)
{
for (pair<string, string> keyValue : obj.s_data) {
oss << "{" << keyValue.first << ": " << keyValue.second << "}" << endl;
}
return oss;
}
I thank you in advance !