I have an Exception base class that defines a stream function:
class Exception { public: template <typename TData, typename TException> TException& stream(const TData& data) { stream_ << data; return *reinterpret_cast<TException*>(this); } };
I have a free function overload operator <:
template <typename TData> Exception& operator<<(Exception& ex, const TData& data) { return ex.stream<TData, Exception>(data); }
I also have an exception exception overload operator <:
template <typename TData> CoffeeException& operator<<(CoffeeException& ex, const TData& data) { return ex.stream<TData, CoffeeException>(data); }
I use it like this:
else { throw CoffeeException() << "Exception text"; }
When I try to use a class, the compiler does not see this function, it just offers the standard flow operators available, but does not notice that my Exception or CoffeeException functions are free. Does this implementation look right?
source share