Top-Level const
A pointer who is const is top-level const,
and the object it point to is const ,it is low-level
pointer must point to an object,not a value.
pointer pointe to an const object may not be initialize,but const pointer must be intialized when defined.
- Top-level indicates that an object itself is const, and appear in any object type.
- Low-level const only appear in the base type of compiund type such as pointer and reference
- when copy an object top-level const will be ipnored
- when copy an object low-level const must be the same ,because it cann’t be ignored
Constexpr
- constexpr : a expression whose value can nor chage and can be evaluated at compile time
- a constant expression is one that can be evaluated at compile time
- define a pointer in a constexprdeclaration, the constexpr specifier applies to the pointer, not the type to which the pointer points
|
|
constexpr impose a top-level const on the object it defines
2.5Type
Typedef type alias : a synonymm for another type.
simplyfy complicated type definitions,emphasize the purpose for which a type ia used.
An alias by c++11
1using SI = Sales_item; // SI is a synonym for Sales_item
auto
- auto let the compiler to deduce the type from the initializer
- auto adjusts the type to conform to normal initialization rules.
auto sz = 0, pi = 3.14; the compiler cann`t deduce the type of the two variable.
- when we use a reference or pointer as a initializer,
we are using the object to which it refers or pointe.
int i = 0, &r = i;
3.auto orfinarily ignores top-level consts.
auto a = r; // a is an intif want to deduce type have a top-level *const*,you must say explicitlly.
const auto
decltype :return the type of its operand.
The compiler analyzes the expression to determine its type but does not evaluate the expression1decltype(f()) sum = x; // sum has whatever type f returns
- If we wrap the variable’s name in one
or more sets of parentheses, the compiler will evaluate the operand as an expression
Assignment is an example of an expression that yields a reference type.
|
|
- decltype returns the type of that variable, including top-level const and references,which auto ignors.
- decltype and auto is that the deduction done by decltype depends on the form of its given expression.