i have a class with a overladed operators.
class sout { public: template<typename T> friend inline sout& operator&(sout&, T&); friend inline sout& operator&(sout&, std::string&); }; now if i use the templated operator& inside the the sting.operator& i get an error:
code:
sout& operator&(sout& s, std::string& str) { uint16_t ts = static_cast<uint16_t>(str.size()); // this is ok s & ts; // is also ok s & static_cast<uint16_t>(str.size()); // but this is wrong // ... return s; } error:
Error:C2679: binary '&' : no operator found which takes a right-hand operand of type 'uint16_t' (or there is no acceptable conversion) could be 'sout &operator &<uint16_t>(sout &,T &)' with [ T=uint16_t ] or 'sout &operator &(sout &,std::string &)' while trying to match the argument list '(sout, uint16_t)' than i tried to use the explicite operator& template-type by:
operator&<uint16_t>(s, ts); // this also ig ok but if i combine it, i again a error:
operator&<uint16_t>(s, static_cast<uint16_t>(str.size()) error:
'operator &' : cannot convert parameter 2 from 'uint16_t' to 'uint16_t &' i also tried reinterpret_cast.
i know operator& is expecting a reference to uint16_t and the size() function is returning a size_t (int) not a reference. is it possible to do that in one line?