HP aC++/HP C Programmer's Guide (B3901-90036; A.06.26; September 2011)

Usage
The ANSI/ISO C++ International Standard states that values of type bool are either
true or false. There are no signed, unsigned, short, or long bool types or values.
bool values behave as integral types and participate in integral promotions. Types bool,
char, wchar_t, and the signed and unsigned integer types are collectively called
integral types. A synonym for integral type is integer type. The representations of integral
types shall define values by use of a pure binary numeration system.
Example
int main(){
bool b=true; // Declare a variable of type bool and set it to true.
if (b) // Test value of bool variable.
b=false; // Set it to false.
}
dynamic_cast Keyword
The keyword dynamic_cast is used in expressions to check the safety of a type cast
at runtime. It is the simplest and most useful form of runtime type identification. You can
use it to cast safely within a class hierarchy based on the runtime type of objects that are
polymorphic types (classes including at least one virtual function). At runtime, the
expression being cast is checked to verify that it points to an instance of the type being
cast to.
Usage
A dynamic cast is most often used to cast from a base class pointer to a derived class
pointer in order to invoke a function appearing only in the derived class. Virtual functions
are preferred when their mechanism is sufficient. Usually a dynamic cast is necessary
because the base class is being specialized, but cannot (or should not) be modified.
Example
class Base {
virtual void f(); // Make Base a polymorphic type.
// other class details omitted
};
class Derived : public Base {
// class details omitted
};
void Base::f()
{
// define Base function
}
int main()
{
172 Standardizing Your Code