HP aC++/HP C Programmer's Guide (B3901-90036; A.06.26; September 2011)
// Message: The left side of ‘=’
// must be a modifiable lvalue.
c1.j = 1; // OK
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 can’t 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
178 Standardizing Your Code