Skip to content

Commit

Permalink
  • Loading branch information
huihut committed Mar 18, 2021
1 parent f279fe8 commit cd9f4df
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -805,11 +805,12 @@ public:
```

#### 动态多态(运行期期/晚绑定)

* 虚函数:用 virtual 修饰成员函数,使其成为虚函数
* 动态绑定:当使用基类的引用或指针调用一个虚函数时将发生动态绑定

**注意:**

* 可以将派生类的对象赋值给基类的指针或引用,反之不可
* 普通函数(非类成员函数)不能是虚函数
* 静态函数(static)不能是虚函数
* 构造函数不能是虚函数(因为在调用构造函数时,虚表指针并没有在对象的内存空间中,必须要构造函数调用完成后才会形成虚表指针)
Expand Down
2 changes: 2 additions & 0 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,11 @@ public:
#### Dynamic polymorphism (runtime / late binding)

* Virtual functions: decorate member functions with virtual to make them virtual
* Dynamic binding: dynamic binding occurs when a virtual function is called using a reference or pointer to a base class

**note:**

* You can assign an object of a derived class to a pointer or reference of the base class, and not vice versa
* Ordinary functions (non-class member functions) cannot be virtual functions
* Static functions (static) cannot be virtual functions
* The constructor cannot be a virtual function (because when the constructor is called, the virtual table pointer is not in the object's memory space, the virtual table pointer must be formed after the constructor is called)
Expand Down

0 comments on commit cd9f4df

Please sign in to comment.