Unqualified name lookups and the using directive
As of z/OS V1R10 XL C++ compiler, the location of the using directive determines how function calls are resolved.
Figure 1 provides an example of code that will
be compiled differently by z/OS V1R10 XL C++ compiler than it was
by earlier XL C++ compilers.
Figure 1. Example
of code with a using directive
Prior to z/OS V1R10 XL C++ compiler, the compiler would resolve
the call to the function sp1 in the namespace bb even
though the statement using namespace bb; is not located
before the function is called inside the main routine. }namespace bb {
double sp1(double) { return 1.0; }
}
int main()
{
double sp1(double);
sp1(0);
return 0;
}
using namespace bb;
In the example in Figure 1, the declaration of sp1 in the main function is a declaration in the global namespace. As of z/OS V1R10 XL C++ compiler, the compiler will resolve that function call to the declaration in the global namespace. Because the definition of sp1 is missing in the global namespace, the binder will generate an error message.
To avoid the error at bind time, you can modify the example in Figure 1 in any of the following ways:
- Explicitly resolve the function call to sp1 in the namespace bb by using the namespace qualifier in the function call
- Implicitly resolve the function call to sp1 in the namespace bb by moving the using directive above the main routine.
- Make the function definition available in the global namespace.
For examples of the using directive in a sample program, see CCNUBRC and CLB3ATMP.CPP. These are documented in z/OS XL C/C++ User's Guide.