I have a custom class called Stream
class Stream
public:
Stream& operator<<(int i) { stream_ << i; return *this;}
template <typename CustomClass>
Stream& operator<<(const CustomClass& c) { stream_ << c.toString() /* assume this template always have toString(); return *this; }
private:
std::stringstream stream_;
};
This is a very basic example of what I actually have. And I am trying to set std::ios_base flags like following:
Stream() << 1 << std::hex << 2;
using operator;
Stream& operator<<(std::ios_base& b) { stream_.setf(b.flags()); return *this; }
from what I understand, because std::hex returns std::ios_base so it should call this and set streams' flag. But it always call the template. Note: If i remove this template, everything works just as good as you would expect but is there a way to have both?
Please feel free to ask further if you need more clarification