HP aC++/HP C A.06.25 Programmer's Guide
NOTE: Using- directives are transitive. If you specify a using- directiveto one
namespace which itself specifies a directive to another namespace, then names used
in your scope will also be looked up in that other namespace.
Using namespace directives can be a powerful means to migrate code to libraries that
use namespaces. Occasionally, however, they may silently make unwanted names
visible. It is therefore often suggested not to use using-directives unless the alternatives
are very inconvenient.
#include <stdio.h>
namespace N {
char const* f() { return “N::f()”; }
char const* f(double) { return “N::f(double)”; }
char const* g() { return “N::g()”; }
}
char const* g(double) {
using N::f; // Declare all f’s in namespace N
return f(2.0);
}
namespace M { // Illustrate how using-directives
using namespace N; // are transitive
}
int main() {
using namespace N;
printf(“Calling: %s.\n”, f()); // calls N::f()
printf(“Calling: %s.\n”, g(1.0)); // calls ::g(double)
// which calls
// N::f(double)
printf(“Calling: %s.\n”, N::g()); // calls N::g()
printf(“Calling: %s.\n”, M::f()); // calls N::f()
return 0;
}
typeid Keyword
The typeid keyword is an operator, called the type identification operator, used to
access type information at runtime. The operator takes either a type name or an
expression and returns a reference to an instance of type_info, a standard library
class.
Usage
You can use runtime type identification when you need to know the exact type of an
object. This might, for example, be necessary to find the name of the object class for
HP aC++ Keywords 191