Implicit conversions

来自cppreference.com
< cpp‎ | language

 
 
C++语言
大会的主题
原文:
General topics
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
流量控制
原文:
Flow control
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
条件执行语句
原文:
Conditional execution statements
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
迭代语句
原文:
Iteration statements
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
跳转语句
原文:
Jump statements
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
功能
原文:
Functions
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
函数声明
lambda函数的声明
函数模板
的历史。内嵌说明
异常规范 (已弃用)
noexcept说明 (C++11)
例外
原文:
Exceptions
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
命名空间
原文:
Namespaces
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
类型
原文:
Types
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
decltype specifier (C++11)
规范
原文:
Specifiers
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
CV符
存储时间说明符
constexpr说明 (C++11)
汽车符 (C++11)
alignas说明 (C++11)
初始化
原文:
Initialization
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
原文:
Literals
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
布尔文字
nullptr (C++11)
用户定义的 (C++11)
表达式
原文:
Expressions
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
另一种表示形式
实用工具
原文:
Utilities
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
类型
原文:
Types
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
typedef declaration
声明类型别名 (C++11)
属性 (C++11)
施放
原文:
Casts
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
隐式转换
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-风格和功能转换
内存分配
原文:
Memory allocation
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
原文:
Classes
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
类特定的功能特性
原文:
Class-specific function properties
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
虚函数
覆盖说明 (C++11)
最后说明 (C++11)
明确的 (C++11)
静态的
特殊的成员函数
原文:
Special member functions
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
模板
原文:
Templates
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
类模板
函数模板
模板特化
参数包 (C++11)
杂项
原文:
Miscellaneous
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
内联汇编
 
进行隐式转换时使用某种类型的T1的表达,但接受不接受这种类型的背景下,一些其他类型T2,特别是:
原文:
Implicit conversions are performed whenever an expression of some type T1 is used in context that does not accept that type, but accepts some other type T2, in particular:
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 声明T2作为参数调用函数时,表达式时使用的参数.
    原文:
    When the expression is used as the argument when calling a function that is declared with T2 as parameter.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 当表达式作为操作数与运营商,预计T2
    原文:
    When the expression is used as an operand with an operator that expects T2
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 当初始化一个新的T2类型的对象,包括return声明一个函数返回T2.
    原文:
    When initializing a new object of type T2, including return statement in a function returning T2.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 当表达式用于在switch语句(T2是积分型)
    原文:
    When the expression is used in a switch statement (T2 is integral type)
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • if声明表达式时使用的一个循环(T2bool
    原文:
    When the expression is used in an if statement or a loop (T2 is bool)
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
该计划是良好的(编译)仅当存在一个明确的“隐式转换序列”从T1T2
原文:
The program is well-formed (compiles) only if there exists one unambiguous implicit conversion sequence from T1 to T2.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
如果有多个被调用的函数或运算符的重载,后是建立从T1到每个可用T2的隐式转换序列,重载决议规则决定了编译过载.
原文:
If there are multiple overloads of the function or operator being called, after the implicit conversion sequence is built from T1 to each available T2, 重载决议 rules decide which overload is compiled.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

目录

[编辑] 转换的顺序

隐式转换序列由以下的顺序是:
原文:
Implicit conversion sequence consists of the following, in this order:
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
1)
零个或一个“标准转换序列”
原文:
zero or one standard conversion sequence
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
2)
零个或一个“用户定义的转换”
原文:
zero or one user-defined conversion
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
3)
零个或一个标准转换序列
原文:
zero or one standard conversion sequence
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
考虑的参数的构造函数或用户定义的转换功能时,只有一个标准转换序列是允许的(否则用户定义的转换,可以有效地链接)。当从一个内置的类型转换到另一个内置的类型,只有一个标准转换序列允许.
原文:
When considering the argument to a constructor or to a user-defined conversion function, only one standard conversion sequence is allowed (otherwise user-defined conversions could be effectively chained). When converting from one built-in type to another built-in type, only one standard conversion sequence is allowed.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
标准转换序列由以下的顺序是:
原文:
A standard conversion sequence consists of the following, in this order:
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
1)
零个或一个“左值变换”
原文:
zero or one lvalue transformation
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
2)
零个或一个“数字升级”或“数字转换”
原文:
zero or one numeric promotion or numeric conversion
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
3)
零个或一个“资格调整”
原文:
zero or one qualification adjustment
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
用户定义的转换包括:
原文:
A user-defined conversion consists of:
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
@ * @零个或一个非显式的单参数的构造函数或显式转换函数调用
原文:
@*@ zero or one non-explicit single-argument constructor or non-explicit conversion function call
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
表达式e被说成是“隐式转换为T2”当且仅当声明T2 t=e;是良好的(可以编译),一些发明的临时t。请注意,这是T2 t(e),明确的构造函数和转换功能,另外考虑不同.
原文:
An expression e is said to be implicitly convertible to T2 if and only if the declaration T2 t=e; is well-formed (can be compiled), for some invented temporary t. Note that this is different from T2 t(e), where explicit constructors and conversion functions would additionally be considered.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
唯一的例外是上面的规则是在以下五个上下文(C++11 起),类型bool特殊的隐式转换调用
原文:
One exception is the above rule is the special implicit conversion invoked in the following five contexts (C++11 起), where type bool is expected:
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 控制表达式ifwhilefor
    原文:
    controlling expression of if, while, for
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 逻辑运算符!&&||
    原文:
    the logical operators !, && and ||
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 条件运算符?:
    原文:
    the conditional operator ?:
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • static_assert
  • noexcept
在这样的背景下,如果声明bool t(e);建立良好的隐式转换序列。即,显式的用户定义的转换函数,如explicit T::operator bool() const;被认为。这样的表达e被说成是“上下文转换为布尔.
原文:
in such contexts, implicit conversion sequence is built if the declaration bool t(e); is well-formed. that is, the explicit user-defined conversion function such as explicit T::operator bool() const; is considered. Such expression e is said to be contextually convertible to bool.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 左值的转换

左值转换时所应用的左值参数(如参照对象)的背景下,右值(如数字),预计.
原文:
Lvalue transformations are applied when lvalue argument (e.g. reference to an object) is used in context where rvalue (e.g. a number) is expected.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 左值到右值的转换

一个glvalue任何非功能,非数组类型T可以隐式地转换为相同类型的prvalue。 T是一种非类类型,这种转换也移除cv修饰符。除非遇到非计算环境(操作数的大小,typeid的,noexcept,或decltype),这种转换有效地复制构造一个临时对象类型T使用原来的glvalue作为构造函数的参数,并,临时对象作为prvalue返回的。 ,如果glvalue的类型std::nullptr_t,prvalue是空指针常量nullptr.
原文:
A glvalue of any non-function, non-array type T can be implicitly converted to prvalue of the same type. If T is a non-class type, this conversion also removes cv-qualifiers. Unless encountered in unevaluated context (in an operand of sizeof, typeid, noexcept, or decltype), this conversion effectively copy-constructs a temporary object of type T using the original glvalue as the constructor argument, and that temporary object is returned as a prvalue. If the glvalue has the type std::nullptr_t, the resulting prvalue is the null pointer constant nullptr.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 数组到指针的转换

一个左值或右值类型的数组“NT”或“未知边界的T阵列”可以被隐式地转换为一个prvalue的指针“类型T”。结果指针的数组的第一个元素是指.
原文:
A lvalue or rvalue of type "array of N T" or "array of unknown bound of T" can be implicitly converted to a prvalue of type "pointer to T". The resulting pointer refers to the first element of the array.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 函数指针

左值可以隐式转换函数类型T到prvalue指向该函数的指针。这并不适用于非静态成员函数,因为非静态成员函数的左值,不存在.
原文:
An lvalue of function type T can be implicitly converted to a prvalue pointer to that function. This does not apply to non-static member functions because lvalues that refer to non-static member functions do not exist.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 数字的促销活动

[编辑] 积分的推广

Prvalues​​小的整类型(如char),可转换为更大的整数类型(如int),prvalues​​的。特别是,算术运算符不接受类型的小于int作为参数,并整体促销会自动应用。这种转换总是保留的价值.
原文:
Prvalues of small integral types (such as char) may be converted to prvalues of larger integral types (such as int). In particular, 算术运算符 do not accept types smaller than int as arguments, and integral promotions are automatically applied. This conversion always preserves the value.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
下列隐式转换被归类为整型的提升
原文:
The following implicit conversions are classified as integral promotions:
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • signed charsigned short可以转换为int.
    原文:
    signed char or signed short can be converted to int.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • unsigned charunsigned short可以转换为unsigned int.
    原文:
    unsigned char or unsigned short can be converted to unsigned int.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • char可以转换为intunsigned int的基本类型:signed charunsigned char(见上文)
    原文:
    char can be converted to int or unsigned int depending on the underlying type: signed char or unsigned char (see above)
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • wchar_tchar16_tchar32_t可以转化为第一种类型从下面的列表中能够保持他们的整个值范围:intunsigned intlongunsigned longlong longunsigned long long.
    原文:
    wchar_t, char16_t, and char32_t can be converted to the first type from the following list able to hold their entire value range: int, unsigned int, long, unsigned long, long long, unsigned long long.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 从下面的列表中能够保持其整个价值范围的“”无作用域的枚举类型是不固定的,其基本型可转换为第一类:intunsigned intlongunsigned longlong long,或unsigned long long。如果该值的范围是更大的,没有整体的促销活动.
    原文:
    An unscoped enumeration type whose underlying type is not fixed can be converted to the first type from the following list able to hold their entire value range: int, unsigned int, long, unsigned long, long long, or unsigned long long. If the value range is greater, no integral promotions apply.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 促进基础类型可以转换为一个“无作用域的枚举”类型的基础类型是固定的。 (C++11 起)
    原文:
    An unscoped enumeration type whose underlying type is fixed can be converted to its promoted underlying type. (C++11 起)
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • A“位域类型”可以转换为int,如果它能够代表整个位域的值的范围,否则unsigned int,如果它可以代表整个位域的值的范围,否则无积分优惠.
    原文:
    A bitfield type can be converted to int if it can represent entire value range of the bitfield, otherwise to unsigned int if it can represent entire value range of the bitfield, otherwise no integral promotions apply.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 与该值可以被转换成的类型boolintfalse成为0true成为1.
    原文:
    The type bool can be converted to int with the value false becoming 0 and true becoming 1.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 浮点推广

可转换类型float甲prvalue prvalue类型double。值不改
原文:
A prvalue of type float can be converted to prvalue of type double. The value does not change.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 数字的转换

不同的促销活动,可能会改变数字转换的值,与潜在的精度损失.
原文:
Unlike the promotions, numeric conversions may change the values, with potential loss of precision.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 积分转换

一个prvalue一个整数类型或无作用域的枚举类型可以转换为任何其他整数类型。如果转换被列在积分促销,它是一种促进,而不是转换.
原文:
A prvalue of an integer type or of an unscoped enumeration type can be converted to any other integer type. If the conversion is listed under integral promotions, it is a promotion and not a conversion.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 如果目标类型是无符号的,所产生的价值是值模2n
    n是数位用来表示目标类型。在2的补码运算(C + +编译器可在所有平台上使用),这种转换是一个no-op,除了截断如果目标类型是小的
    原文:
    If the destination type is unsigned, the resulting value is the value modulo 2n
    where n is the number of bits used to represent the destination type. In 2's complement arithmetic (used on all platforms where C++ compilers are available), this conversion is a no-op, except for the truncation if the destination type is to small.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 如果目标类型是有符号的值不会改变,如果源整数可以表示目标类型的。否则,其结果是实现定义的.
    原文:
    If the destination type is signed, the value does not change if the source integer can be represented in the destination type. Otherwise the result is implementation-defined.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 如果源类型为bool,被转换的值false到零,并转换的目标类型(注意,如果目标类型是true,这是一个整数的推广,而不是一个整数的转换)的值1的值int
    原文:
    If the source type is bool, the value false is converted to zero and the value true is converted to the value one of the destination type (note that if the destination type is int, this is an integer promotion, not an integer conversion)
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 如果目标类型是bool,这是一个布尔值转换(见下文)
    原文:
    If the destination type is bool, this is a boolean conversion (see below)
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 浮点转换

一个prvalue的浮点类型可以转换为任何其他浮点类型prvalue。如果转换被列入下浮点促销,它是一种促进,而不是转换.
原文:
A prvalue of an floating-point type can be converted to prvalue of any other floating-point type. If the conversion is listed under floating-point promotions, it is a promotion and not a conversion.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 如果源值可以精确表示目标类型,它不改
    原文:
    If the source value can be represented exactly in the destination type, it does not change.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 如果源值是表示两个值的目标类型,其结果是这两个值之一(这是实现定义的是哪一个)
    原文:
    If the source value is between two representable values of the destination type, the result is one of those two values (it is implementation-defined which one)
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 否则,该行为是未定义.
    原文:
    Otherwise, the behavior is undefined.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 浮动 - 整体转换

  • 一个prvalue的浮点类型可以转换为任何整数类型的prvalue。的小数部分被截断,即,​​小数部分被丢弃。如果该值不能放入目标类型,其行为是不确定的。如果目标类型是bool,这是一个布尔值转换(见下文).
    原文:
    A prvalue of floating-point type can be converted to prvalue of any integer type. The fractional part is truncated, that is, the fractional part is discarded. If the value can not fit into the destination type, the behavior is undefined. If the destination type is bool, this is a boolean conversion (see below).
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 一个prvalue的整数或无作用域的枚举类型可以转换为任何浮点类型的prvalue。如果该值不能正确地表示,这是实现定义的最接近是否高于或最接近的低表示的值将被选中。如果该值不能放入目标类型,其行为是不确定的。如果源类型为bool,被转换的值false为零,和的值被转换成一个true.
    原文:
    A prvalue of integer or unscoped enumeration type can be converted to prvalue of any floating-point type. If the value can not be represented correctly, it is implementation defined whether the closest higher or the closest lower representable value will be selected. If the value can not fit into the destination type, the behavior is undefined. If the source type is bool, the value false is converted to zero, and the value true is converted to one.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 指针转换

  • “空指针常量”NULL或任何其他prvalue的积分类型,其值为零或任何prvalue的类型std::nullptr_t,包括“空指针文字nullptr,可转换为任何指针类型,其结果是该类型的空指针值。允许这样的转换(称为“空指针转换”转换TOT的cv-限定的类型为单次转换,也就是说,它不认为是一个组合的数字和合格的转换).
    原文:
    The null pointer constant NULL or any other prvalue of integral type that evaluates to zero or any prvalue of type std::nullptr_t, including the null pointer literal nullptr, can be converted to any pointer type, and the result is the null pointer value of that type. Such conversion (known as 'null pointer conversion is allowed to conver tot a cv-qualified type as a single conversion, that is, it's not considered a combination of numeric and qualifying conversions).
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 阿prvalue指向任何(可选CV合格)对象类型T可以被转换成一个prvalue指针,以(相同品种合格)的voidT如果不是的运行时类型指向的对象,所得到的指针调整为指向最派生的对象所占用的存储的开始。如果原来的指针是一个空指针值,其结果是一个空指针目标类型.
    原文:
    A prvalue pointer to any (optionally cv-qualified) object type T can be converted to a prvalue pointer to (identically cv-qualified) void. If T is not the runtime type of the pointed-to object, the resulting pointer is adjusted to point to the start of the storage occupied by the most-derived object. If the original pointer is a null pointer value, the result is a null pointer value of the destination type.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 一个prvalue指向一个(任选品种合格的)派生类类型可以转换为prvalue其可访问的,明确的(相同的CV合格)的基类的指针。转换的结果是一个指针所指向的对象的基类的子对象内。空指针值转换为目标类型的空指针值.
    原文:
    A prvalue pointer to a (optionally cv-qualified) derived class type can be converted to prvalue pointer to its accessible, unambiguous (identically cv-qualified) base class. The result of the conversion is a pointer to the base class subobject within the pointed-to object. The null pointer value is converted to the null pointer value of the destination type.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 指针到成员的转换

  • “空指针常数NULL或任何其他prvalue的积分类型,其值为零或任何prvalue的std::nullptr_t的类型,包括”空指针文字nullptr,可以转换为任何指针到成员的类型,和结果是​​该类型的空指针值。允许这样的转换(称为“空指针转换”转换TOT的cv-限定的类型为单次转换,也就是说,它不认为是一个组合的数字和合格的转换).
    原文:
    The null pointer constant NULL or any other prvalue of integral type that evaluates to zero or any prvalue of type std::nullptr_t, including the null pointer literal nullptr, can be converted to any pointer-to-member type, and the result is the null pointer value of that type. Such conversion (known as 'null pointer conversion is allowed to conver tot a cv-qualified type as a single conversion, that is, it's not considered a combination of numeric and qualifying conversions).
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 在基类中T某种类型的B成员Prvalue指针可以转换,以prvalue相同类型的T在它的派生类D成员的指针。 B是无法访问的,如果含糊不清,或虚拟基础D或是一些中间虚基类D的基础,转化是形成不良(不能编译)。结果指针被解除引用一个D对象,B基地内,D对象的子对象的,它会访问该成员。空指针值转换为目标类型的空指针值.
    原文:
    Prvalue pointer to member of some type T in a base class B can be converted to prvalue pointer to member of the same type T in its derived class D. If B is inaccessible, ambiguous, or virtual base of D or is a base of some intermediate virtual base of D, the conversion is ill-formed (won't compile). The resulting pointer can be dereferenced with a D object, and it will access the member within the B base subobject of that D object. The null pointer value is converted to the null pointer value of the destination type.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 布尔转换

Prvalues​​可以转换为整数,浮点,无作用域的枚举,指针,指针到成员类型的prvalues​​类型bool.
原文:
Prvalues of integral, floating-point, unscoped enumeration, pointer, and pointer-to-member types can be converted to prvalues of type bool.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
零值(整型,浮点型点,无作用域的枚举)和空指针和空指针到成员的值成为false。所有其他值成为true.
原文:
The value zero (for integral, floating-point, and unscoped enumeration) and the null pointer and the null pointer-to-member values become false. All other values become true.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
prvalue类型std::nullptr_t包括nullptr,可以转换prvalue类型bool。所得到的值是false(C++11 起)
原文:
Prvalue of type std::nullptr_t, including nullptr, can be converted to prvalue of type bool. The resulting value is false. (C++11 起)
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 资格转换

  • 一个prvalue指针类型的CV-限定的类型T在课堂上X的成员可以转换为prvalue指针成员CV-限定的类型TX.
    原文:
    A prvalue of type pointer to member of cv-qualified type T in class X can be converted to prvalue pointer to member of more cv-qualified type T in class X.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
“”CV合格的手段
原文:
"More" cv-qualified means that
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • “不合格”类型可以转换const
    原文:
    unqualified type can be converted to const
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • “不合格”类型可以转换volatile
    原文:
    unqualified type can be converted to volatile
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • “不合格”类型可以转换const volatile
    原文:
    unqualified type can be converted to const volatile
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • const类型可以转换const volatile
    原文:
    const type can be converted to const volatile
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • volatile类型可以转换const volatile
    原文:
    volatile type can be converted to const volatile
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
对于多层次的指针,有下列限制:
原文:
For multi-level pointers, the following restrictions apply:
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
一个多层次的P1合格的cv1
0
合格的指针的指针的指针cv1
1
,... cv1
n-1
合格的cv1
n
T合格的指针转换为一个多层次的P1合格的cv2
0
合格的指针的指针的指针cv2
1
... cv2
n-1
cv2
n
合格的T只有合格的指针
原文:
A multilevel pointer P1 which is cv1
0
-qualified pointer to cv1
1
-qualified pointer to ... cv1
n-1
-qualified pointer to cv1
n
-qualified T is convertible to a multilevel pointer P1 which is cv2
0
-qualified pointer to cv2
1
-qualified pointer to ... cv2
n-1
-qualified pointer to cv2
n
-qualified T only if
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 水平n的数目是相同的两个指针
    原文:
    The number of levels n is the same for both pointers
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 在P1的一些电平(电平零除外)如果有一个constcv1
    k
    资格,有一个在相同等级的P2constcv2
    k
    原文:
    If there is a const in the cv1
    k
    qualification at some level (other than level zero) of P1, there is a const in the same level cv2
    k
    of P2
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 如果有一个在一定程度上(除零级)的P1volatilecv1
    k
    资格,有一个在相同的P2volatilelevelcv2
    k
    原文:
    If there is a volatile in the cv1
    k
    qualification at some level (other than level zero) of P1, there is a volatile in the same cv2
    k
    level of P2
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 如果在一定程度上是不同的k的cv资格之间P1P2,那么就必须是一个const在每一个(其他零级以上)P2起来,直到K:cv2
    1
    , cv2
    2
    ... cv2
    k
    .
    原文:
    If at some level k the cv-qualifications are different between P1 and P2, then there must be a const at every single level (other than level zero) of P2 up until k: cv2
    1
    , cv2
    2
    ... cv2
    k
    .
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 规则同样适用于多层次的成员,多层次混合的对象和指向成员的指针的指针的指针.
    原文:
    Same rules apply to multi-level pointers to members and multi-level mixed pointers to objects and pointers to members.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • 零级解决非多层次的资格转换的规则.
    原文:
    Level zero is addressed by the rules for non-multilevel qualification conversions.
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
特别是,这不允许从T**转换const T**,但允许转换const T* const*.
原文:
In particular, this forbids the conversion from T** to const T**, but conversion to const T* const* is allowed.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 安全BOOL问题

直到引进的显式转换函数在C + +11,设计一个类,应该是在布尔上下文中使用(例如if(obj) { ...提出了一个问题:给定一个用户定义的转换功能,如T::operator bool() const;,隐式转换序列允许一个另外的标准转换序列后,该函数调用,这意味着可以转换所得boolint,允许这样的代码作为obj << 1;int i=test;.
原文:
Until the introduction of explicit conversion functions in C++11, designing a class that should be usable in boolean contexts (e.g. if(obj) { ... presented a problem: given a user-defined conversion function, such as T::operator bool() const;, the implicit conversion sequence allowed one additional standard conversion sequence after that function call, which means the resultant bool could be converted to int, allowing such code as obj << 1; or int i=test;.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
一个早期的解决方案中可以看到std::basic_ios,这定义operator!operator void*()(至 C++11)的,从而使代码如if(std::cin) {...编译,因为void*转换为bool,但int n = std::cout;不编译void*是转换为intdelete std::cout;编译的代码,如仍允许废话,和之前的很多C + +11第三方库的设计与更精细的溶液,被称为Safe Bool idiom.
原文:
One early solution for this can be seen in std::basic_ios, which defines operator! and operator void*()(至 C++11), so that the code such as if(std::cin) {... compiles because void* is convertible to bool, but int n = std::cout; does not compile because void* is not convertible to int. This still allows nonsense code such as delete std::cout; to compile, and many pre-C++11 third party libraries were designed with a more elaborate solution, known as the Safe Bool idiom.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 另请参阅