If I have have some overloaded ostream operators, defined for library local objects, is its okay for them to go to std namespace? If I do not declare them in std namespace, then I must use using ns:: operator <<.
As a possible follow-up question, are there any operators which should go to standard or global namespace?
According to Koenig Lookup (C++ Standard 3.4.2) operator<< will be searched in namespaces of arguments. No need to declare it in std namespace.
operator<<( ..., MyClass ) should go in the same namespace as MyClass. You should think of it as part of the interface of MyClass, even though it happens to be (necessarily) a non-member function.
A couple of references:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With