I declared a global shift operator but for some reason the compiler cannot deduct the type.
template<class T, size_t N>
std::istream& operator >>(std::istream& stream, std::array<T, N>& array);
Instead it tries to use a overload with std::istream&& as the first argument.
EDIT: I invoke via
void myns::subns::Object::Func(std::istream& stream) {
stream >> array;
}
where array is std::array<size_t, 2>.
Indeed, when I try it isolated it compiles – but in my code gcc (4.7) complains error: cannot bind ‘std::istream {aka std::basic_istream<char>}’ lvalue to ‘std::basic_istream<char>&&’
Could someone explain to me why the deduction does not work or how I can force to call the function overload?
If it doesn’t find the
operator>>in the namespace it is called from, the compiler looks for the operator in namespaces associated with the parameters you use. In this case they all come from namespace std, and not from the global namespace. Therefore the global namespace is not searched.When you explicitly call
::operator>>(istream, array), it does look in the global namespace (as you specifically asked it to).