本文主要介绍const修饰符在C++中的主要用法,下面会从两个方面进行介绍:类定义中使用const.非类定义中使用const 1. 非类定义中使用const 非类定义中使用const是指:在除了类定义以外的场景中使用const. 1.1 变量 const int a = 1; //定义一个常量,不可以修改 int b = 2; //定义一个普通变量,可以修改 const int &b = a; //定义一个常量引用,不可以通过引用b修改a,底层const const int *p = &a…
Value categories Three primary categories primary categories mixed special Each C++ expression (an operator with its operands, a literal, a variable name, etc.) is characterized by two independent properties: a type and a value category. Each express…
Rvalue references are a feature of C++ that was added with the C++11 standard. The syntax of an rvalue reference is to add && after a type. In C++, there are rvalues and lvalues. An lvalue is an expression whose address can be taken,a locator valu…
Object lifetime Temporary object lifetime Storage reuse Access outside of lifetime Every object has a lifetime, which is a runtime property: for any object, there is a moment during the execution of a program when its lifetime begins, and there is a…