const_cast<type_id> (expression)
The operator is used to modify the const or volatile properties of a type. In addition to const or volatile adornments, the type_id and expression types are the same.
A constant pointer is converted into a very good pointer, and still points to the original object;
The constant reference is converted to a very literal reference and still points to the original object;
static_cast<type-id> (expression)
The operator converts expression to the Type-id type, but does not have run-time type checking to guarantee the security of the conversion. It is mainly used in the following ways:
① is used for the conversion of pointers or references between base classes (parent classes) and derived classes (subclasses) in a class hierarchy.
It is safe to make an upstream conversion (to convert a pointer or reference from a derived class to a base class representation).
When you make a downstream conversion (a base class pointer or reference is converted to a derived class representation), it is unsafe because there is no dynamic type checking.
② is used for conversions between basic data types, such as converting int to char, and converting int to enum. The security of this conversion is also to be ensured by the developer.
③ converts a null pointer to a null pointer of the target type.
④ converts any type of expression to a void type.
Note: static_cast cannot convert the const, volatile, or __unaligned properties of expression.
If the keyword const appears to the left of the asterisk *, it indicates that the object is a constant, and if it appears to the right of the asterisk, the pointer itself is a constant, and if it appears on both sides of the asterisk, both the finger and the pointer are constants.
Char greeting[]= "Hello";
char* p=greeting;
Const char* p=greeting; Const data
char* Const p=greeting; Const pointer
const char* Const p=greeting; const pointer, const data
Std::vector<int> VEC;
Const Std::vector<int>::iterator Iter=vec.begin (); ITER like a t* const pointer
Std::vector<int>::const_iterator Citer=vec.begin (); ITER like a const t* pointer
mutable
Member variables that are modified by mutable can always be changed, even within the const member function.