《C++ Primer》的原文摘录

  • If we have not previously told the compiler that the friend is a template, then the compiler will infer that the friend is an ordinary nontemplate class or function. 如果没有事先告诉编译器该友元是一个模板,则编译器将认为该友元是一个普通非模板类或非模板函数。 (查看原文)
    1赞 2012-09-02 12:15:00
    —— 引自章节:类模板的嵌套类中的友元声明(friend declarati
  • A friend declaration introduces the named class or nonmember function into the surrounding scope. Moreover, a friend function may be defined inside the class. The scope of the function is exported to the scope enclosing the class definition. 友元声明将已命名的类或非成员函数引入到外围作用域中。此外,友元函数可以在类的内部定义,该函数的作用域扩展到包围该类定义的作用域。 (查看原文)
    1赞 2012-09-02 12:15:00
    —— 引自章节:类模板的嵌套类中的友元声明(friend declarati
  • to make a member function a friend, the class containing that member must have been defined. 必须先定义包含成员函数的类,才能将成员函数设为友元。 When we want to restrict friendship to a specific instantiation, then the class or function must have been declared before it can be used in a friend declaration 想要限制对特定实例化的友元关系时,必须在可以用于友元声明之前声明类或函数 (查看原文)
    1赞 2012-09-02 12:15:00
    —— 引自章节:类模板的嵌套类中的友元声明(friend declarati
  • 可以将严格弱序看作"小于等于" •两个关键字不能同时"小于等于"对方;如果k1"小于等于"k2, 那么 k2 决不能"小于等于" k1 . (查看原文)
    Laserss 1回复 2赞 2016-04-28 19:00:42
    —— 引自第378页
  • We can think of a strict weak ordering as “less than” • Two keys cannot both be “less than” each other; if k1 is “less than” k2, then k2 must never be “less than” k1. (查看原文)
    Laserss 1回复 2赞 2016-04-28 19:00:42
    —— 引自第378页
  • Unlike using declarations for ordinary members, a constructor using declaration does not change access level of the inherited constructor(s). More over, a using declaration can't specify explicit or constexpr, the inherited constructor has the same property as the corresponding base constructor. (查看原文)
    晨星 2赞 2020-01-15 01:08:27
  • An inherited constructor is not treated as a user-defined constructor. Therefore, a class that contains only inherited constructors will have a synthesized default constructor. (查看原文)
    晨星 2赞 2020-01-15 01:08:27
  • 4.3.2. 新旧代码的兼容 许多 C++ 程序在有标准类之前就已经存在了,因此既没有使用标准库类型 string 也没有使用 vector。而且,许多 C++ 程序为了兼容现存的 C 程序,也 不能使用 C++ 标准库。因此,现代的 C++ 程序经常必须兼容使用数组和/或 C 风格字符串的代码,标准库提供了使兼容界面更容易管理的手段。 194 混合使用标准库类 string 和 C 风格字符串 正如第 3.2.1 节中显示的,可用字符串字面值初始化 string 类对象: string st3("Hello World"); // st3 holds Hello World 通常,由于 C 风格字符串与字符串字面值具有相同的数据类型,而且都是以 空字符 null 结束,因此可以把 C 风格字符串用在任何可以使用字符串字面值 的地方: • 可以使用 C 风格字符串对 string 对象进行初始化或赋值。 • string 类型的加法操作需要两个操作数,可以使用 C 风格字符串作为其 中的一个操作数,也允许将 C 风格字符串用作复合赋值操作的右操作数。 反之则不成立:在要求 C 风格字符串的地方不可直接使用标准库 string 类 型对象。例如,无法使用 string 对象初始化字符指针: char *str = st2; // compile-time type error 但是,string 类提供了一个名为 c_str 的成员函数,以实现我们的要求: char *str = st2.c_str(); // almost ok, but not quite c_str 函数返回 C 风格字符串,其字面意思是:“返回 C 风格字符串的表 示方法”,即返回指向字符数组首地址的指针,该数组存放了与 string 对象相 同的内容,并且以结束符 null 结束... (查看原文)
    月出渐分明 2012-12-20 15:53:55
    —— 引自第121页
  • array<int, 10> a1 = {0,1,2,3,4,5,6,7,8,9}; array<int, 10> a2 = {0}; // elements all have value 0 a1 = a2; // replaces elements in a1 a2 = {0}; // error: cannot assign to an array from a braced list (查看原文)
    永久欠番💙 1赞 2017-08-07 16:14:52
    —— 引自第338页
  • Classes generated from a lambda expression have a deleted default constructor, deleted assignment operators, and a default destructor. Whether the class has a default or deleted copy/move constructor depends in the usual ways on the types of the captured data members. (查看原文)
    晨星 1赞 2020-01-05 03:15:20
    —— 引自章节:14.8 Function-CallOperator . .
  • 1. Candidate functions: identifies the set of overloaded functions considered for the call. 2. Viable functions: select from the set of candidate functions those functions that can be called with the arguments in the given call. 3. Best Match: determines which viable function provide the best match for the call. (查看原文)
    晨星 2019-11-09 15:51:28
    —— 引自章节:Chapter 6 Functions . . . . .
  • There is an overall best match if there is one and only one function for which * The match for each argument is no worse than the match required by any other viable function. * There is at least one argument for which the match is better than the match provided by any other viable function. (查看原文)
    晨星 2019-11-09 16:57:47
    —— 引自章节:6.6 FunctionMatching . . . . .
  • Conversions are ranked as follows: 1. Exact match. An exact match happens when: * Identical; * Array/function to pointer; * Add or remove top-level const. 2. Const conversion (low-level) 3. Promotion 4. Arithmetic or pointer conversion. 5. Class-type conversion. (查看原文)
    晨星 2019-11-09 17:01:21
    —— 引自章节:6.6 FunctionMatching . . . . .
  • Unlink what happens to parameters that have function type, the return type is not automatically converted to a pointer type. We must explicitly specify that the return type is a pointer type. (查看原文)
    晨星 2019-11-10 01:52:36
    —— 引自章节:6.7 Pointers toFunctions . . .
  • In an abstract data type, the class designer worries about how the class is implemented. Programmers who use the class need not know how the type works. They can instead think abstractly about what the type does. (查看原文)
    晨星 2019-11-10 01:56:32
    —— 引自章节:Chapter 7 Classes . . . . . .
  • A well designed class has an interface that is intuitive and easy to use and has an implementation that is efficient enough for its intended use. (查看原文)
    晨星 2019-11-10 02:00:13
    —— 引自章节:7.1 DefiningAbstractDataTypes
  • The "= default" can appear with the declaration inside the class body or on the definition outside the class body. Like any other function, if the "= default" appears inside the class body, the default constructor will be inlined; if it appears on the definition outside the class, the member will not be inlined by default. (查看原文)
    晨星 2019-11-11 02:21:58
    —— 引自章节:7.1 DefiningAbstractDataTypes
  • Friends are not members of the class and are not affected by the access control of the section in which they are declared. (查看原文)
    晨星 2019-11-12 00:58:35
    —— 引自章节:7.3 AdditionalClassFeatures .
  • Unlike ordinary members, members that define types must appear before they are used. (查看原文)
    晨星 2019-11-12 01:01:09
    —— 引自章节:7.3 AdditionalClassFeatures .
  • Parameters and return type of a constexpr function must be literal types. Unlike other classes, classes that are literal types may have function members that are constexpr. An aggregate class whose data members are all of literal type is a literal class. A nonaggregate class, that meets the following restrictions, is also a literal class. * The data members all must have literal type. * The class must have at least one constexpr constructor. * If a data member has an in-class initializer, the initializer for a member of build-in type must be a constant expression, or if the member has class type, the initializer must use the member's own constexpr constructor. * The class must use default definition for its destructor. (查看原文)
    晨星 2019-11-17 01:25:34
    —— 引自章节:7.5 ConstructorsRevisited . .
<前页 1 2 3 4 5 6 7 8 9 ... 24 25 后页>