The code fails on the last line, i.e. the explicit call of operator<<() on the next-to-last line works OK - as does using the overloaded operator outside the namespace (in test1()).
Can anyone explain what is going on here and/or help me to fix this, please?
I don't think so - the compiler finds error on the last line of test_oper.cpp. In other words, the operator<< exists and works OK, if I use the explicit call by VecMat::operator<<().
Since the operator works also for test1(), my guess is that the problem is that test2() is in namespace Main, while the operator is in namespace VecMat. But why should this depend on existence of the extra operator<< in test_other.hpp, I really have no idea :-(
@Michal That sounds about right, seems when Main::operator<< is defined your overload in the other namespace is hidden. I think the best you could do is put using VecMat::operator<<; inside your Main namespace.
Also, it wouldnt hurt to create a test case and open a question over @stackoverflow.