The Wayback Machine - https://web.archive.org/web/20130627090016/http://zh.cppreference.com:80/w/cpp/language

C++ language

来自cppreference.com
< cpp

 
 
C + +语言
大会的主题
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
流量控制
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
条件执行语句
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
迭代语句
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
跳转语句
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
功能
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
函数声明
lambda函数的声明
函数模板
的历史。内嵌说明
异常规范 (过时了)
noexcept说明 (C++11)
例外
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
命名空间
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
类型
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decltype specifier (C++11)
规范
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
CV符
存储时间说明符
constexpr说明 (C++11)
汽车符 (C++11)
alignas说明 (C++11)
初始化
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
布尔文字
nullptr (C++11)
用户定义的 (C++11)
表达式
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
另一种表示形式
实用工具
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
类型
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
声明类型别名 (C++11)
属性 (C++11)
施放
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
隐式转换
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-风格和功能转换
内存分配
Original:
Memory allocation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
类特定的功能特性
Original:
Class-specific function properties
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
虚函数
覆盖说明 (C++11)
最后说明 (C++11)
明确的 (C++11)
静态的
特殊的成员函数
Original:
Special member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
模板
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
类模板
函数模板
模板特化
参数包 (C++11)
杂项
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
内联汇编
 

这是一份C++语言结构的简单参考。

目录

[编辑] 一般性主题

[编辑] 预处理器

[编辑] 注释

[编辑] 关键字

[编辑] ASCII表

[编辑] 转义序列

[编辑] C++历史

[编辑] 程序流控制

[编辑] 条件执行语句

条件语句根据给定的表达式的值执行不同的代码路径。
Original:
Conditional statements execute different code paths according to the value of given expression.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • if有条件地执行代码
    Original:
    ifexecutes code conditionally
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • switch执行代码的整体参数的值
    Original:
    switch executes code according to the value of an integral argument
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

[编辑] 迭代语句

迭代语句多次执行一个代码路径。
Original:
Iteration statements execute a code path multiple times.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • for 通过制定初始化,比较和增量执行循环。
    Original:
    for executes loops by specifying initialization, comparison, and increment
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • range-for 在某个范围内执行循环(C++11 起)
    Original:
    range-for executes loops over a range(C++11 起)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • while 执行循环,并在每次迭代之前检查是否符合条件
    Original:
    while executes loop, checking condition before each iteration
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • do-while 执行循环,并在每次迭代后检查是否符合条件
    Original:
    do-while executes loop, checking condition after each iteration
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

[编辑] 跳转语句

跳转语句使程序在不同的位置执行.
Original:
Jump statements continue program execution at a different location.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • continue跳过封闭的循环体的剩余部分
    Original:
    continue skips the remaining part of the enclosing loop body
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • break结束的封闭循环
    Original:
    break terminates the enclosing loop
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • goto在其他位置继续执行
    Original:
    goto continues execution in another location
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • return终止执行的封闭功能
    Original:
    return terminates execution of the enclosing function
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

[编辑] 函数

可以在程序中的不同的位置重复使用的相同代码。
Original:
The same code can be reused at different locations in the program.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 异常

例外的是一个更强大的方式来发出错误信息。函数的返回代码或全局错误变量的条件比.
Original:
Exceptions are a more robust way to signal error condition than function return codes or global error variables.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 命名空间

命名空间提供了一种在大型项目以避免名称冲突的方法。
Original:
Namespaces provide a way to prevent name clashes in large projects.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 类型

  • 基本类型 定义基本的字符型,整型和浮点类型
    Original:
    fundamental types define basic character, integer and floating point types
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 指针类型 定义一个存储内存位置的类型
    Original:
    pointer types define types holding a memory location
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • compound types 定义有几个数据成员(本质上是相同的“类”)的类型
    Original:
    compound types define types that hold several data members (essentially the same as class)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 枚举类型定义类型能够保持只有一个指定的值
    Original:
    enumeration types define types that are able to hold only one of the specified values
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 联合类型定义,可容纳数表示的数据的类型
    Original:
    union types define types that can hold data in several representations
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 函数类型定义函数调用签名,那是类型的参数和返回类型
    Original:
    function types define function call signatures, that is the types of arguments and the return type
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • decltype说明相当于一个表达式(C++11 起)类型定义了一个类型
    Original:
    decltype specifier defines a type equivalent to the type of an expression (C++11 起)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

[编辑] 限定符

  • cv限定符指定类型的常量性和波动性
    Original:
    cv specifiers specify constness and volatility of types
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 存储时间说明符指定类型的存储时间
    Original:
    storage duration specifiers specify storage duration of types
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • constexpr说明指定的变量或函数的值可以在编译时(C++11 起)计算
    Original:
    constexpr specifier specifies that the value of a variable or function can be computed at compile time (C++11 起)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 自动符指定的表达,分配给变量(C++11 起)的实际类型应定义
    Original:
    auto specifier specifies that the actual type shall be defined from the expression, assigned to the variable (C++11 起)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • alignas说明指定的变量的存储空间应​​保持一致的具体数额(C++11 起)
    Original:
    alignas specifier specifies that the storage for the variable should be aligned by specific amount (C++11 起)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

[编辑] 初始化

每当命名的变量的声明,每当创建一个临时对象,新对象的初始值是通过以下机制之一
Original:
Whenever a named variable is declared, and whenever a temporary object is created, the initial value of the new object is provided through one of the following mechanisms:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 常值

文字是一个C++程序,代表恒定值,在源代码中嵌入的标记.
Original:
Literals are the tokens of a C++ program that represent constant values, embedded in the source code.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • 整数文字是十进制,八进制或十六进制数字的整数类型.
    Original:
    integer literals are decimal, octal, or hexadecimal numbers of integer type.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 字符文字是单个字符类型charchar16_tchar32_t,或wchar_t
    Original:
    character literals are individual characters of type char, char16_t, char32_t, or wchar_t
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 浮点文字类型floatdouble,或long double的值
    Original:
    floating-point literals are values of type float, double, or long double
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 字符串文字的字符序列,这可能是狭隘的,多字节或宽
    Original:
    string literals are sequences of characters, which may be narrow, multibyte, or wide
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 布尔文字是值类型bool,这是truefalse
    Original:
    boolean literals are values of type bool, that is true and false
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • nullptr文字的指针,它指定一个空指针(C++11 起)
    Original:
    nullptr is the pointer literal which specifies a null pointer value (C++11 起)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 用户自定义的文字用户指定的类型是恒定值(C++11 起)
    Original:
    user-defined literals are constant values of user-specified type (C++11 起)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

[编辑] 表达式

符和操作数指定的计算表达式可以是一个序列。表达可能会导致一个值,并可能引起副作用.
Original:
An expression is a sequence of operators and operands that specifies a computation. An expression can result in a value and can cause side effects.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • 价值类型(左值,右值,glvalue,prvalue,xvalue)分类表达它们的值
    Original:
    value categories (lvalue, rvalue, glvalue, prvalue, xvalue) classify expressions by their values
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 为了评价的参数和子表达式指定的顺序在中间结果
    Original:
    order of evaluation of arguments and subexpressions specify the order in which intermediate results are obtained
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • operators允许使用的语法中常见的数学
    Original:
    operators allow the use of syntax commonly found in mathematics
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
Common operators
分配 incrementNJdecrement 算术 合乎逻辑的 比较 memberNJaccess 其他

a = b
a = rvalue
a += b
a -= b
a *= b
a /= b
a %= b
a &= b
a |= b
a ^= b
a <<= b
a >>= b

++a
--a
a++
a--

+a
-a
a + b
a - b
a * b
a / b
a % b
~a
a & b
a | b
a ^ b
a << b
a >> b

!a
a && b
a || b

a == b
a != b
a < b
a > b
a <= b
a >= b

a[b]
*a
&a
a->b
a.b
a->*b
a.*b

a(...)
a, b
(type) a
? :

Special operators
static_cast将一种类型转换到另一个兼容的类型
Original:
static_cast converts one type to another compatible type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
dynamic_cast将虚基类到派生class
Original:
dynamic_cast converts virtual base class to derived class
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
const_cast转换类型兼容型,与不同的cvqualifiers
Original:
const_cast converts type to compatible type with different cv qualifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
reinterpret_cast转换类型不兼容的type
Original:
reinterpret_cast converts type to incompatible type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
new个分配memory
Original:
new allocates memory
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
delete会释放memory
Original:
delete deallocates memory
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
sizeof查询的大小的type
Original:
sizeof queries the size of a type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
sizeof...查询的大小的参数组(C++11 起)
Original:
sizeof... queries the size of a 参数组 (C++11 起)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typeid查询的类型一个type
信息
Original:
typeid queries the type information of a type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
noexcept进行检查,,如果的表达可以抛出一个异常(C++11 起)
Original:
noexcept checks if an expression can throw an exception (C++11 起)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
alignof查询类型(C++11 起)对齐要求
Original:
alignof queries alignment requirements of a type (C++11 起)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 实用工具

类型
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
强制转换
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
内存分配
Original:
Memory allocation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑]

类提供了面向对象编程的概念在C + +
Original:
Classes provide the concept of object-oriented programming in C++.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • 类的声明声明类
    Original:
    class declarations declare classes
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • this指针的当前实例中的类成员方法
    Original:
    this pointer links to the current instance of a class in member methods
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 访问符确定类成员的可见性
    Original:
    access specifiers determine visibility of class members
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 朋友说明授予访问权限的私有/受保护的部分非会员的类或函数
    Original:
    friend specifier grants access privileges to private/protected parts for non-member classes or functions
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 初始化列表初始化类成员的数据
    Original:
    initializer lists initialize class member data
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

[编辑] 类特定的功能特性

  • 虚函数的说明声明一个函数是虚拟的
    Original:
    virtual function specifier declares that a function is virtual
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 覆盖说明声明一个虚函数重写另一个虚拟function.(C++11 起)
    Original:
    override specifier declares that a virtual function overrides another virtual function.(C++11 起)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 最后说明声明一个虚函数不能被覆盖一个继承class.(C++11 起)
    Original:
    final specifier declares that a virtual function can not be overridden in a inheriting class.(C++11 起)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 明确的功能说明声明构造函数或转换运算符不能用于隐式转换(C++11 起)
    Original:
    explicit function specifier declares that a constructor or conversion operator can not be used in implicit conversions (C++11 起)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 静态函数说明声明一个函数不使用类的数据
    Original:
    static function specifier declares that a function does not use class data
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • CV功能说明声明一个成员函数只能用于品种限定对象
    Original:
    cv function specifier declares that a member function can only be used on cv qualified objects
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

[编辑] 特殊的成员函数

  • 默认构造函数 初始化的对象默认内容
    Original:
    default constructor initializes the object with default contents
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • copy constructor初始化的对象与另一个对象的内容
    Original:
    copy constructor initializes the object with the contents of another object
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 移动的构造函数初始化其他临时对象的内容的对象,最大限度地减少复制开销(C++11 起)
    Original:
    move constructor initializes the object with the contents of other, temporary object, minimizing copying overhead (C++11 起)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 赋值运算符替换的对象与另一个对象的内容的内容
    Original:
    assignment operator replaces the contents of the object with the contents of another object
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 移动赋值运算符替换其他临时对象的内容的对象的内容,最大限度地减少复制开销(C++11 起)
    Original:
    move assignment operator replaces the contents of the object with the contents of other, temporary object, minimizing copying overhead (C++11 起)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 析构函数版本声称资源
    Original:
    destructor releases claimed resources
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

[编辑] 模板

允许函数和类,泛型类型的操作
Original:
Allows functions and classes to operate on generic types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 优化

  • 因为如果规则 可以不改变任何代码转换的输出
    Original:
    The as-if rule allows any code transformation that doesn't change the output
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 复制省略 ,包括RVO和NRVO,使传递的值在许多情况下,首选的方法.
    Original:
    Copy elision, including RVO and NRVO, makes pass-by-value the preferred approach in many situations.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • 空基类优化 多重继承,接口或策略类的开销,并须为标准布局类型.
    Original:
    Empty base optimization makes multiple inheritance from interfaces or policy classes overhead-free and is required for standard-layout types.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

[编辑] 杂项

  • 内联汇编允许使用的汇编代码,,沿着C + +代码
    Original:
    Inline assembly allows the use of assembly code alongside C++ code
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.