### 显式限定数组实参的元素个数

A declaration of a parameter as "array of type" shall be adjusted to "qualified pointer to type".

int x[3][5];Here x is a 3 × 5 array of integers. When x appears in an expression, it is converted to a pointer to (the first of three) five-membered arrays of integers.

### 启用编译器的改变符号的隐式类型转换警告

if中的那段表达式是为true的(输出yes)，而且编译时也不会发出警告。

The usual arithmetic conversions are performed on operands of arithmetic or enumeration type.

Warnings about conversions between signed and unsigned integers are disabled by default in C++ unless -Wsign-conversion is explicitly enabled.

Warn for implicit conversions that may change the sign of an integer value, like assigning a signed integer expression to an unsigned integer variable. An explicit cast silences the warning. In C, this option is enabled also by -Wconversion.

### 断言(assert)

If NDEBUG is defined as a macro name at the point in the source code where <assert.h> is included, then assert does nothing.
If NDEBUG is not defined, then assert checks if its argument (which must have scalar type) compares equal to zero.

cppreference - assert
assert只在Debug模式中有效，使用release模assert什么都不做了。

### 无效的引用

in particular, a null reference cannot exist in a well-defined program, because the only way to create such a reference would be to bind it to the “object” obtained by indirection through a null pointer,which causes undefined behavior.

### 忽略函数参数的顶层cv-qualifier

<function> name, parameter type list (8.3.5), and enclosing namespace (if any)

[ISO/IEC 14882:2014 §8.3.5.5]After producing the list of parameter types, any top-level cv-qualifiers modifying a parameter type are deleted when forming the function type. The resulting list of transformed parameter types and the presence or absence of the ellipsis or a function parameter pack is the function’s parameter-type-list.

### struct tag (*[5])(float)

The type designated as ‘‘struct tag (*[5])(float)’’ has type ‘‘array of pointer to function returning struct tag’’. The array has length five and the function has a single parameter of type float. Its type category is array.

### 底层(Low-Level)const和顶层(Top-Level)const

• 对于int const *x=std::nullput;，const修饰的是*x，因为x是指针，我们就暂且把此处的*x当做解引用来看，他就代表x所指向的对象，则它就是底层const
• 反之亦然，int * const x=std::nullptr;，因为const修饰的是指针x，所以它就是顶层const

### 在构造函数中传递this指针的危害

During the construction of a const object, if the value of the object or any of its subobjects is accessed through a glvalue that is not obtained, directly or indirectly, from the constructor’s this pointer, the value of the object or subobject thus obtained is unspecified.

### 到底有几种传参方式

• 传值(by value)：形参的值是实参的拷；
• 传引用(by reference)：形参是实参的别名；
• 传指针(by pointer)：传递指向对象的指针给形参；

Unless a formal argument(parameter) is a reference, a copy of the actual argument is passed to the function.

### 引用的实现

C++标准中是这么解释引用的:

[ISO/IEC 14882:2014 §8.3.2]A reference can be thought of as a name of an object.

### STL容器中压缩容量和真正地删除元素

STL中的std::remove算法并不真正地从容器中删除元素。因为std::remove属于algorithm，只操作迭代器范围，不掉用容器的成员函数，所以是不可能从容器中真正删除元素的。

### 宏的替代

C++中几乎从不需要宏。可以用const和enum定义易于理解的常量。用inline来避免函数调用的开销，用template指定函数系列和类型系列，用namespace避免名字冲突。

### 类内内存分配函数

C++中类内的内存分配函数都是static成员函数:

Any allocation function for a class T is a static member (even if not explicitly declared static).

### 异常安全

1. 析构函数、operator new、operator delete不能抛出异常
2. swap操作不要抛出异常
3. 首先做任何可能抛出异常的事情(但不会改变对象重要的状态)，然后以不会抛出异常的操作结束。
4. 当一个被抛出的异常从throw表达式奔向catch子句时，所经之路任何一个部分执行的函数比从执行堆栈上移除其激活记录之前，都必须清理他所控制的任何资源。
5. 不要在代码中插入可能会提前返回的代码、调用可能会抛出异常的函数、或者插入其他一些东西从而使得函数末尾的资源释放得不到执行。

### std::vector的随机访问

std::vector可以随机访问，因为其重载了[]操作符，以及有at成员函数，则通常有下面两种方式：

[ISO/IEC 14882:2014]The member function at() provides bounds-checked access to container elements. at() throws out_of_range if n >= a.size().
operator[]标准中则没有任何要求。

### 继承层次中的类查询

The result of the expression dynamic_cast<T>(v) is the result of converting the expression v to type T. T shall be a pointer or reference to a complete class type, or “pointer to cv void.” The dynamic_cast operator shall not cast away constness (5.2.11).

If C is the class type to which T points or refers, the run-time check logically executes as follows:

• If, in the most derived object pointed (referred) to by v, v points (refers) to a public base class subobject of a C object, and if only one object of type C is derived from the subobject pointed (referred) to by v the result points (refers) to that C object.
• Otherwise, if v points (refers) to a public base class subobject of the most derived object, and the type of the most derived object has a base class, of type C, that is unambiguous and public, the result points (refers) to the C subobject of the most derived object.
• Otherwise, the run-time check fails.

The value of a failed cast to pointer type is the null pointer value of the required result type. A failed cast to reference type throws an exception (15.1) of a type that would match a handler (15.3) of type std::bad_cast (18.7.2).

### 在使用列表初始化时initializer_List构造函数优先级比普通构造函数高

List-initialization is initialization of an object or reference from a braced-init-list. Such an initializer is called an initializer list.
initializer-list constructor: A constructor is an initializer-list constructor if its first parameter is of type std::initializer_list<E> or reference to possibly cv-qualified std::initializer_list<E> for some type E, and either there are no other parameters or else all other parameters have default arguments (8.3.6).

Note: Initializer-list constructors are favored over other constructors in list-initialization (13.3.1.7).

[ISO/IEC 14882:2014 13.3.1.7 Initialization by list-initialization] When objects of non-aggregate class type T are list-initialized (8.5.4), overload resolution selects the constructor in two phases:

• Initially, the candidate functions are the initializer-list constructors (8.5.4) of the class T and the
argument list consists of the initializer list as a single argument.
• If no viable initializer-list constructor is found, overload resolution is performed again, where the
candidate functions are all the constructors of the class T and the argument list consists of the elements of the initializer list.

If the initializer list has no elements and T has a default constructor, the first phase is omitted. In copy-list-initialization, if an explicit constructor is chosen, the initialization is ill-formed. [ Note: This differs from other situations (13.3.1.3, 13.3.1.4), where only converting constructors are considered for copy-initialization. This restriction only applies if this initialization is part of the final result of overload resolution. - end note ]

1. 优先匹配构造函数参数为initializer-list的构造函数，如果initializer-list中没有元素并且该类有一个默认构造函数，则该步被忽略。
2. 如果找不到可行的initializer-list构造函数，重新执行重载解析，候选函数为Class的所有构造函数，参数列表由initializer-list的元素组成。