I made my own stream class inherited from std::ostream with a template insertion operator:
class MyOstream : public std::ostream
{
...
template <typename T>
std::ostream & operator << (T value)
{
...
return std::ostream::operator<<(value);
}
}
Also, I have a function that gets a reference to a std::ostream as an argument:
void some_func(std::ostream & stream)
{
stream << "Hello World!";
}
I want to somehow call MyOstream::operator<<() in some_func(), but the problem is that std::ostream::operator<<() is not virtual (actually, there are multiple overloaded operators + several friend operators) and I can't override it as usual.
Is there any way to do this without changing the interface of some_func()?
Addition
Function some_func(...) gets an object of MyOstream class as a parameter.
Addition #2
Actually I have my own MyStreambuf inherited from std::streambuf, which provides all the logic, MyOstream class is just needed to access to binary data. MyStreambuf class is used to restrict size of data, that user can write (let it be 500B). So, if object of MyStreambuf currently contains 450B of data and user will try to write 100B it'll cause setting of std::ios_base::badbit and refusing data. If user then try to write 10B, which is absolutely valid, it fails, cause of badbit set. That is the real problem.
So, the real problem I'm trying to overcome is calling clear() before each attempt to write.