Skip to content

Commit

Permalink
Style: 移除结尾空格
Browse files Browse the repository at this point in the history
  • Loading branch information
czs108 committed May 28, 2020
1 parent c25ad4f commit 580726d
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 92 deletions.
2 changes: 1 addition & 1 deletion Chapter-10 Generic Algorithms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ cout << f() << endl; // prints 42

```c++
// get an iterator to the first element whose size() is >= sz
auto wc = find_if(words.begin(), words.end(),
auto wc = find_if(words.begin(), words.end(),
[sz](const string &a) { return a.size() >= sz; });
```

Expand Down
2 changes: 1 addition & 1 deletion Chapter-12 Dynamic Memory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ weak_ptr<int> wp(p); // wp weakly shares with p; use count in p is unchanged

```c++
if (shared_ptr<int> np = wp.lock())
{
{
// true if np is not null
// inside the if, np shares its object with p
}
Expand Down
6 changes: 3 additions & 3 deletions Chapter-13 Copy Control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Sales_data
public:
// other members and constructors as before
// declaration equivalent to the synthesized copy constructor
Sales_data(const Sales_data&);
Sales_data(const Sales_data&);
private:
std::string bookNo;
int units_sold = 0;
Expand Down Expand Up @@ -213,7 +213,7 @@ public:
ps(new std::string(*p.ps)), i(p.i) { }
HasPtr& operator=(const HasPtr &);
~HasPtr() { delete ps; }

private:
std::string *ps;
int i;
Expand Down Expand Up @@ -489,7 +489,7 @@ Foo z(std::move(x)); // copy constructor, because there is no move constructo
```c++
// assignment operator is both the move- and copy-assignment operator
HasPtr& operator=(HasPtr rhs)
{
{
swap(*this, rhs);
return *this;
}
Expand Down
10 changes: 5 additions & 5 deletions Chapter-14 Overloaded Operations and Conversions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public:
{
os << s << sep;
}

private:
ostream &os; // stream on which to write
char sep; // character to print after each output
Expand All @@ -296,7 +296,7 @@ printer(s); // prints s followed by a space on cout
如果类定义了调用运算符,则该类的对象被称作函数对象(function object),函数对象常常作为泛型算法的实参。

```c++
for_each(vs.begin(), vs.end(), PrintString(cerr, '\n'));
for_each(vs.begin(), vs.end(), PrintString(cerr, '\n'));
```

### lambda是函数对象(Lambdas Are Function Objects)
Expand Down Expand Up @@ -335,10 +335,10 @@ public:
SizeComp(size_t n): sz(n) { } // parameter for each captured variable
// call operator with the same return type, parameters, and body as the lambda
bool operator()(const string &s) const
{
return s.size() >= sz;
{
return s.size() >= sz;
}

private:
size_t sz; // a data member for each variable captured by value
};
Expand Down
2 changes: 1 addition & 1 deletion Chapter-16 Templates and Generic Programming/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public:
void push_back(const T &t) { data->push_back(t); }
void push_back(T &&t) { data->push_back(std::move(t)); }
// ...

private:
std::shared_ptr<std::vector<T>> data;
};
Expand Down
4 changes: 2 additions & 2 deletions Chapter-18 Tools for Large Programs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ namespace A
return i; // returns B::i
}
} // namespace B is closed and names in it are no longer visible

int f2()
{
return j; // error: j is not defined
Expand Down Expand Up @@ -713,7 +713,7 @@ class Panda : public Bear, public Raccoon, public Endangered { /* ... */ };
```c++
Bear::Bear(std::string name, bool onExhibit)
: ZooAnimal(name, onExhibit, "Bear") { }

Raccoon::Raccoon(std::string name, bool onExhibit)
: ZooAnimal(name, onExhibit, "Raccoon") { }

Expand Down
14 changes: 7 additions & 7 deletions Chapter-19 Specialized Tools and Techniques/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ dynamic_cast<type&&>(e)
```c++
void f(const Base &b)
{
try
try
{
const Derived &d = dynamic_cast<const Derived&>(b);
// use the Derived object to which b referred
Expand Down Expand Up @@ -343,8 +343,8 @@ int j = peppers::red; // error: scoped enumerations are not implicitly convert

```c++
enum intValues : unsigned long long
{
/*...*/
{
/*...*/
};
```

Expand Down Expand Up @@ -376,7 +376,7 @@ public:
char get_cursor() const { return contents[cursor]; }
char get() const;
char get(pos ht, pos wd) const;

private:
std::string contents;
pos cursor;
Expand Down Expand Up @@ -496,7 +496,7 @@ class TextQuery
};

// we're defining the QueryResult class that is a member of class TextQuery
class TextQuery::QueryResult
class TextQuery::QueryResult
{
/*...*/
};
Expand Down Expand Up @@ -580,7 +580,7 @@ void foo(int val)
static int si;
enum Loc { a = 1024, b };
// Bar is local to foo
struct Bar
struct Bar
{
Loc locVal; // ok: uses a local type name
int barVal;
Expand Down Expand Up @@ -608,7 +608,7 @@ void foo()
public:
class Nested; // declares class Nested
};

// definition of Nested
class Bar::Nested
{
Expand Down
30 changes: 15 additions & 15 deletions Chapter-2 Variables and Basic Types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### 算数类型(Arithmetic Types)

算数类型分为两类:整型(integral type)、浮点型(floating-point type)。
算数类型分为两类:整型(integral type)、浮点型(floating-point type)。

![2-1](Images/2-1.png)

Expand Down Expand Up @@ -50,20 +50,20 @@ for (unsigned u = 10; u >= 0; --u)
std::cout << u << std::endl;
```

当*u*等于0时,*--u*的结果将会是4294967295。一种解决办法是用`while`语句来代替`for`语句,前者可以在输出变量前先减去1
当*u*等于0时,*--u*的结果将会是4294967295。一种解决办法是用`while`语句来代替`for`语句,前者可以在输出变量前先减去1

```c++
unsigned u = 11; // start the loop one past the first element we want to print
while (u > 0)
while (u > 0)
{
--u; // decrement first, so that the last iteration will print 0
std::cout << u << std::endl;
}
```

不要混用带符号类型和无符号类型。
不要混用带符号类型和无符号类型。

### 字面值常量(Literals)
### 字面值常量(Literals)

以`0`开头的整数代表八进制(octal)数,以`0x`或`0X`开头的整数代表十六进制(hexadecimal)数。在C++14中,`0b`或`0B`开头的整数代表二进制(binary)数。

Expand All @@ -81,9 +81,9 @@ std::cout << 1'100'000; // 输出"1100000"

由单引号括起来的一个字符称为`char`型字面值,双引号括起来的零个或多个字符称为字符串字面值。

字符串字面值的类型是由常量字符构成的数组(array)。编译器在每个字符串的结尾处添加一个空字符`'\0'`,因此字符串字面值的实际长度要比它的内容多一位。
字符串字面值的类型是由常量字符构成的数组(array)。编译器在每个字符串的结尾处添加一个空字符`'\0'`,因此字符串字面值的实际长度要比它的内容多一位。

转义序列:
转义序列:

| 含义 | 转义字符 |
| :-------------: | :------: |
Expand All @@ -104,14 +104,14 @@ std::cout << '\n'; // prints a newline
std::cout << "\tHi!\n"; // prints a tab followd by "Hi!" and a newline
```
泛化转义序列的形式是`\x`后紧跟1个或多个十六进制数字,或者`\`后紧跟1个、2个或3个八进制数字,其中数字部分表示字符对应的数值。如果`\`后面跟着的八进制数字超过3个,则只有前3个数字与`\`构成转义序列。相反,`\x`要用到后面跟着的所有数字。
泛化转义序列的形式是`\x`后紧跟1个或多个十六进制数字,或者`\`后紧跟1个、2个或3个八进制数字,其中数字部分表示字符对应的数值。如果`\`后面跟着的八进制数字超过3个,则只有前3个数字与`\`构成转义序列。相反,`\x`要用到后面跟着的所有数字。
```c++
std::cout << "Hi \x4dO\115!\n"; // prints Hi MOM! followed by a newline
std::cout << '\115' << '\n'; // prints M followed by a newline
```
添加特定的前缀和后缀,可以改变整型、浮点型和字符型字面值的默认类型。
添加特定的前缀和后缀,可以改变整型、浮点型和字符型字面值的默认类型。
![2-2](Images/2-2.png)
Expand Down Expand Up @@ -195,7 +195,7 @@ int main()
}
```
如果函数有可能用到某个全局变量,则不宜再定义一个同名的局部变量。
如果函数有可能用到某个全局变量,则不宜再定义一个同名的局部变量。
## 复合类型(Compound Type)
Expand Down Expand Up @@ -231,7 +231,7 @@ int *ip1, *ip2; // both ip1 and ip2 are pointers to int
double dp, *dp2; // dp2 is a pointer to double; dp is a double
```
指针存放某个对象的地址,要想获取对象的地址,需要使用取地址符`&`。
指针存放某个对象的地址,要想获取对象的地址,需要使用取地址符`&`。
```c++
int ival = 42;
Expand Down Expand Up @@ -300,7 +300,7 @@ r = &i; // r refers to a pointer; assigning &i to r makes p point to i
*r = 0; // dereferencing r yields i, the object to which p points; changes i to 0
```
面对一条比较复杂的指针或引用的声明语句时,从右向左阅读有助于弄清它的真实含义。
面对一条比较复杂的指针或引用的声明语句时,从右向左阅读有助于弄清它的真实含义。
## const限定符(Const Qualifier)
Expand Down Expand Up @@ -378,7 +378,7 @@ const double pi = 3.14159;
const double *const pip = &pi; // pip is a const pointer to a const object
```
指针本身是常量并不代表不能通过指针修改其所指向的对象的值,能否这样做完全依赖于其指向对象的类型。
指针本身是常量并不代表不能通过指针修改其所指向的对象的值,能否这样做完全依赖于其指向对象的类型。
### 顶层const(Top-Level const)
Expand Down Expand Up @@ -484,7 +484,7 @@ auto item = val1 + val2; // item initialized to the result of val1 + val2
auto a = r; // a is an int (r is an alias for i, which has type int)
```
- `auto`一般会忽略顶层`const`。
- `auto`一般会忽略顶层`const`。
```c++
const int ci = i, &cr = ci;
Expand Down Expand Up @@ -548,7 +548,7 @@ C++11规定可以为类的数据成员(data member)提供一个类内初始
#ifndef SALES_DATA_H
#define SALES_DATA_H
#include <string>
struct Sales_data
struct Sales_data
{
std::string bookNo;
unsigned units_sold = 0;
Expand Down
Loading

0 comments on commit 580726d

Please sign in to comment.