Exercise 15.8: Give definitions of static types and dynamic types.
A: Static type: Is the type of the variable declaration, or the type generated by the expression, and the type is known at compile time .
Dynamic type: Is the type of object in memory that is represented by a variable or expression and is not known until run time .
Exercise 15.9: Under what circumstances can the static type of an expression be different from a dynamic type? Please give three different examples of static types and dynamic types.
A: The first type: a function parameter is a reference to a base class (a static type), and when the function is called, the passed argument is the object of the derived class (the dynamic type).
The second type: a function parameter is a pointer to a base class (a static type), and when the function is called, the passed argument is a pointer to the derived class (the dynamic type).
The third type: a function parameter is a pointer to a base class (a static type), and when the function is called, the passed argument is a reference to the object of the derived class (the dynamic type).
C + + Primer Chinese 5th Edition Exercise 15.8 and exercise 15.9 answers