Team LiB
Previous Section Next Section

Defined Terms

术语

arithmetic conversion(算术转换)

A conversion from one arithmetic type to another. In the context of the binary arithmetic operators, arithmetic conversions usually attempt to preserve precision by converting a smaller type to a larger type (e.g., small integral types, such as char and short, are converted to int).

算术类型之间的转换。在使用二元算术操作符的地方,算术转换通常将较小的类型转换为较大的类型,以确保精度(例如,将小的整型 char 型和 short 型转换为 int 型)。

associativity(结合性)

Determines how operators of the same precedence are grouped. Operators can be either right associative (operators are grouped from right to left) or left associative (operators are grouped from left to right).

决定同一优先级的操作符如何结合。C++ 的操作符要么是左结合(操作符从左向右结合)要么是右结合(操作符从右向左结合)。

binary operators(二元操作符)

Operators that take two operands.

有两个操作数的操作符。

cast(强制类型转换)

An explicit conversion.

显式的类型转换。

compound expression(复合表达式)

An expression involving more than one operator.

含有多个操作符的表达式。

const_cast

A cast that converts a const object to the corresponding nonconst type.

const 对象转换为相应的非 const 类型的强制转换。

conversion(类型转换)

Process whereby a value of one type is transformed into a value of another type. The language defines conversions among the built-in types. Conversions to and from class types are also possible.

将某种类型的值转换为另一种类型值的处理方式。C++ 语言定义了内置类型之间的类型转换,也允许将某种类型转换为类类型或将类类型转换为某种类型。

dangling pointer(悬垂指针)

A pointer that refers to memory that once had an object but no longer does. Dangling pointers are the source of program errors that are quite difficult to detect.

指向曾经存在的对象的指针,但该对象已经不再存在了。悬垂指针容易导致程序错误,而且这种错误很难检测出来。

delete expression(delete表达式)

A delete expression frees memory that was allocated by new. There are two forms of delete:

delete 表达式用于释放由 new 动态分配的内存。delete 有两种语法形式:

     delete p;      // delete object
     delete [] p;    // delete array

In the first case, p must be a pointer to a dynamically allocated object; in the second, p must point to the first element in a dynamically allocated array. In C++ programs, delete replaces the use of the C library free function.

第一种形式的 p 必须是指向动态创建对象的指针;第二种形式的 p 则应指向动态创建数组的第一个元素。C++ 程序使用 delete 取代 C 语言的标准库函数 free

dynamic_cast

Used in combination with inheritance and run-time type identification. See Section 18.2 (p. 772).

用于结合继承和运行时类型识别。参见第 18.2 节

expression(表达式)

The lowest level of computation in a C++ program. Expressions generally apply an operator to one or more operands. Each expression yields a result. Expressions can be used as operands, so we can write compound expressions requiring the evaluation of multiple operators.

C++程序中的最低级的计算。表达式通常将一个操作符用于一个或多个操作数。每个表达式产生一个结果。表达式也可用作操作数,因此可用多个操作符编写复合表达式。

implicit conversion(隐式类型转换)

A conversion that is automatically generated by the compiler. Given an expression that needs a particular type but has an operand of a differing type, the compiler will automatically convert the operand to the desired type if an appropriate conversion exists.

编译器自动实现的类型转换。假设表达式需要某种特定类型的数值,但其操作数却是其他不同的类型,此时如果系统定义了适当的类型转换,编译器会自动根据转换规则将该操作数转换为需要的类型。

integral promotions(整型提升)

Subset of the standard conversions that take a smaller integral type to its most closely related larger type. Integral types (e.g. short, char, etc.) are promoted to int or unsigned int.

整型提升是标准类型转换规则的子集,它将较小的整型转换为最接近的较大数据类型。整型(如 shortchar 等)被提升为 int 型或 unsigned int 型。

new expression(new表达式)

A new expression allocates memory at run time from the free store. This chapter looked at the form that allocates a single object:

new 表达式用于运行时从自由存储区中分配内存空间。本章使用 new 创建单个对象,其语法形式为:

     new type;
     new type(inits);

allocates an object of the indicated type and optionally initializes that object using the initializers in inits. Returns a pointer to the object. In C++ programs, new replaces use of the C library malloc function.

new 表达式创建指定 type 类型的对象,并且可选择在创建时使用 inits 初值初始化该对象,然后返回指向该对象的指针。C++ 程序使用 new 取代 C 语言的标准库函数 malloc

operands(操作数)

Values on which an expression

表达式操纵的值。

operator(操作符)

Symbol that determines what action an expression performs. The language defines a set of operators and what those operators mean when applied to values of built-in type. The language also defines the precedence and associativity of each operator and specifies how many operands each operator takes. Operators may be overloaded and applied to values of class type.

决定表达式执行什么功能的符号。C++ 语言定义了一组操作符以及将它们用于内置类型时的含义,还定义了每个操作符的优先级和结合性以及它们所需要的操作数个数。C++ 语言允许重载操作符,以使它们能用于类类型的对象。

operator overloading(操作符重载)

The ability to redefine an operator to apply to class types. We'll see in Chapter 14 how to define overloaded versions of operators.

对操作符的功能重定义以用于类类型。我们将在第十四章中学习如何重载不同的操作符版本。

order of evaluation(求值顺序)

Order, if any, in which the operands to an operator are evaluated. In most cases in C++ the compiler is free to evaluate operands in any order.

操作符的操作数计算顺序(如果有的话)。大多数情况下,C++ 编译器可自由选择操作数求解的次序。

precedence(优先级)

Defines the order in which different operators in a compound expression are grouped. Operators with higher precedence are grouped more tightly than operators with lower precedence.

定义了复合表达式中不同操作符的结合方式。高优先级的操作符要比低优先级操作符结合得更紧密。

reinterpret_cast

Interprets the contents of the operand as a different type. Inherently machine-dependent and dangerous.

将操作数内容解释为另一种不同的类型。这类强制转换本质上依赖于机器,而且是非常危险的。

result(结果)

The value or object obtained by evaluating an expression.

计算表达式所获得的值或对象。

static_cast

An explicit request for a type conversion that the compiler would do implicitly. Often used to override an implicit conversion that the compiler would otherwise perform.

编译器隐式执行的任何类型转换都可以由 static_cast 显式完成。我们常常使用 static_cast 取代由编译器实现的隐式转换。

unary operators(一元操作符)

Operators that take a single operand.

只有一个操作数的操作符。

~ operator

The bitwise NOT operator. Inverts the bits of its operand.

逐位求反操作符,将其操作数的每个位都取反。

, operator

The comma operator. Expressions separated by a comma are evaluated left to right. Result of a comma expression is the value of the right-most expression.

逗号操作符。用逗号隔开的表达式从左向右计算,整个逗号表达式的结果为其最右边的表达式的值。

^ operator

The bitwise exclusive or operator. Generates a new integral value in which each bit position is 1 if either but not both operands contain a 1 in that bit position; otherwise, the bit is 0.

位异或操作符。在做位异或操作时,如果两个操作数对应位置上的位只有一个(注意不是两个)为 1,则操作结果中该位为 1,否则为 0,位异或操作产生一个新的整数值。

| operator

The bitwise OR operator. Generates a new integral value in which each bit position is 1 if either operand has a 1 in that position; otherwise the bit is 0.

位或操作符。在做位或操作时,如果两个操作数对应位置上的位至少有一个为 1,则操作结果中该位为 1,否则为 0,位或操作产生一个新的整数值。

++ operator

The increment operator. The increment operator has two forms, prefix and postfix. Prefix increment yields an lvalue. It adds one to the operand and returns the changed value of the operand. Postfix increment yields an rvalue. It adds one to the operand and returns the original, unchanged value of the operand.

自增操作符。自增操作符有两种形式:前置操作和后置操作。前自增操作生成左值,在给操作数加1后返回改变后的操作数值。后自增操作生成右值,给操作数加1但返回未改变的操作数原值。

-- operator

The decrement operator. has two forms, prefix and postfix. Prefix decrement yields an lvalue. It subtracts one from the operand and returns the changed value of the operand. Postfix decrement yields an rvalue. It subtracts one from the operand and returns the original, unchanged value of the operand.

自减操作符。自减操作符也有两种形式:前置操作和后置操作。前自减操作生成左值,在给操作数减1后返回改变后的操作数值。后自减操作生成右值,给操作数减1但返回未改变的操作数原值。

<< operator

The left-shift operator. Shifts bits in the left-hand operand to the left. Shifts as many bits as indicated by the right-hand operand. The right-hand operand must be zero or positive and strictly less than the number of bits in the left-hand operand.

左移操作符。左移操作符将其左操作数的各个位向左移动若干个位,移动的位数由其右操作数指定。左移操作符的右操作数必须是0值或正整数,而且它的值必须严格小于左操作数的位数。

>> operator

The right-shift operator. Like the left-shift operator except that bits are shifted to the right. The right-hand operand must be zero or positive and strictly less than the number of bits in the left-hand operand.

右移操作符。与左移操作符类似,右移操作符将其左操作数的各个位向右移动,其右操作数必须是0值或正整数,而且它的值必须严格小于左操作数的位数。

Team LiB
Previous Section Next Section