I refer to Stroustrup's slightly vague example in 3.3 Namespaces of 'A Tour of C++'. He gives the following example:
namespace My_Code {
class complex { /* ... */ }; // class complex is within My_Code scope
complex sqrt(complex); //takes our locally-defined complex as an argument
int main();
}
// Defining My_Code main function *outside* of the My_Code namespace,
// but this is fine
int My_Code::main() {
complex z {1, 2}; // My_Code::complex, or std::complex?
auto z2 = sqrt(z); // My_Code::sqrt(), or std::sqrt()?
std::cout << '{' << z2.real() << ',' << z2.imag() << "}\n";
// ...
}
int main() {
return My_Code::main();
}
My question is: having tried this and finding that the expected types are from My_Code, why are the types of z and z2 in this case belonging to My_Code? Surely if we are defining this function outside of the namespace, then we are no longer using our own types without qualification and should be qualifying them? Or does the fact that we're implementing a function from a particular namespace explain this behaviour?