Skip to content

Commit

Permalink
[faq] 优化虚函数调用的解释
Browse files Browse the repository at this point in the history
  • Loading branch information
FeignClaims authored Jun 17, 2024
1 parent 063e3fa commit 8882bb3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions faq/virtual_function_invocation_explain/main.rst
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,11 @@
.. code-block:: cpp
:linenos:
class Derived {
/* Derived 的信息 */
class Base {
/* Base 的信息已经被析构了 */
class Derived {
/* Derived 的信息还在 */
}
}
我们最终泄露了 :cpp:`Derived` 部分的内存. 更可怕的是这实际上是未定义行为, 程序可以做任何事, 甚至炸掉你的电脑!
Expand Down Expand Up @@ -754,4 +757,4 @@
.. admonition:: 相关核心准则
:class: coreguidelines

- :coreguidelines:`C.130: 要进行多态类的深拷贝, 倾向于使用 clone 函数而不是公用拷贝构造/赋值函数 <c130-for-making-deep-copies-of-polymorphic-classes-prefer-a-virtual-clone-function-instead-of-public-copy-constructionassignment>`
- :coreguidelines:`C.130: 要进行多态类的深拷贝, 倾向于使用 clone 函数而不是公用拷贝构造/赋值函数 <c130-for-making-deep-copies-of-polymorphic-classes-prefer-a-virtual-clone-function-instead-of-public-copy-constructionassignment>`

0 comments on commit 8882bb3

Please sign in to comment.