这种初始化和赋值叫什么?

what is this kind of initialization and assignment called?

这个我知道

int value1 = 1; // is copy initialization
double value2(2.2); // is direct initialization
char value3 {'c'}; // is uniform initialization
int value4 = {5}; // is initializer list
value4 = 6; // is copy assignment

我很好奇,这个叫什么?

int value5 = (3);
value5 = (4);
value5 = {5};

对于

int value5 = (3);

copy initialization

T object = other; (1)

1) when a named variable (automatic, static, or thread-local) of a non-reference type T is declared with the initializer consisting of an equals sign followed by an expression.


对于:

value5 = (4);
value5 = {5};

直接赋值。

Assignment operators

copy assignment operator replaces the contents of the object a with a copy of the contents of b (b is not modified). For class types, this is a special member function, described in copy assignment operator.

For non-class types, copy and move assignment are indistinguishable and are referred to as direct assignment.

int value5 = (3);value5 = (4); 仍然是复制赋值,因为右侧被简单地分别计算为 34

另一方面value5 = {5};是复制初始化列表。