In my program I have defined the ostream and am trying to have it call a function that already formatted the output, but it is not working. The error I get is: error: no match for 'operator<<' in 'os << (&duration)->Duration::asString()'
Any help would be appreciated. The code works if I simply erase the asString fucntion and put the code from that directly into the ostream definition but that is not what my instructor is looking for. Thanks.
Your Duration::asString() function returns void and does the printing internally.
So it does not make sense to feed it to os as in: os << duration.asString();
The code works if I simply erase the asString fucntion and put the code from that directly into the ostream definition but that is not what my instructor is looking for.
What is your instructor looking for? Does he want you to create an std::string instead of just printing?
If so, your Duration::asString() must return an std::string, and for simplicity std::stringstream will be used to create the actual string. (Looking at your current code this is probably the goal.)
I was having trouble figuring out how to return the string correctly, since you can't just do: string output = days << ":" << hours << ":" << minutes << ":" << seconds << ":" << ticks;
That's why I did it that way; you're right about what you said.