-
Templates
I can't remember how to do this...
Say you have an operator overload that usually looks like this:
template <typename UnknownType>
any operator <<(const any & lhs, const UnknownType & rhs)
but you want a explicit (I think thats the right word :-)) version of it like this that does something different:
istream& operator <<(ostream & is, any & operand)
How do you do this when you know for sure you want an ostream?
I thought it would be
template <ostream>
ostream& operator <<(ostream & os, const any & operand)
However, it really isn't liking this, as now there are three << overloads:
Code:
template <ostream>
ostream& operator <<(ostream & os, const any & operand)
Code:
template <typename UnknownType>
any operator <<(const any & lhs, const UnknownType & rhs)
Code:
template <typename UnknownType>
UnknownType operator <<(const UnknownType & lhs,const any & rhs)
How do I get it to run a different overload if parameter one is an ostream and parameter two is an any?
I also need it to be able to have parameter one be UnknownType and parameter two be any... the reverse.
-
-
Which function template generates errors?
template <>
ostream& operator <<(ostream & os, const any & operand)
Kuphryn
-
I think the problem is the constructor for the any takes any type... hence the name.
I'll see if making it explicit fixes it, if so, we know what to do.