HP aC++/HP C A.06.25 Programmer's Guide

c2.i = 2; // OK
c2.j = 3; // OK
}
The mutable keyword can only be used on class data members. It cannot be used for
const or static data members. Notice the difference in the two pointer declarations
below:
class C {
C() { } // define constructor
mutable const int *p; // OK
// mutable pointer to int const
// p in constant C object
// can be modified
mutable int *const q; // Compile time error
// mutable const pointer to int
// const data member cant be
// mutable
// Message: mutable may be
// used only in non-static
// and non-constant data
// member declarations within
// class declarations
};
namespace and using Keywords
Namespaces were introduced into C++ primarily as a mechanism to avoid naming
conflicts between various libraries. The following example illustrates how this is
achieved:Every namespace introduces a new scope. By default, names inside a
namespace are hidden from enclosing scopes. Selection of a particular name can be
achieved using the qualified-name syntax. Namespaces can be nested very much like
classes.
#include <stdio.h>
namespace N {
struct Object {
virtual char const* name() const { return Object from N; }
};
}
namespace M {
struct Object {
virtual char const* name() const { return Object from M; }
};
namespace X { // a nested namespace
struct Object: M::Object { // inherit from a class
188 Standardizing Your Code