【发布时间】:2020-11-18 11:59:52
【问题描述】:
在学习“Effective C++”时,当我了解到如果一个类具有多重继承时,我首先感到惊讶的是,当指针转换完成时,它的指针可能会发生偏移。虽然这个概念不太容易掌握,但我想我设法搞定了。
然而,作者声称即使在单个继承类的指针转换中也可能发生这种偏移。我想知道这种情况会是什么,并希望知道其背后的原理。
【问题讨论】:
-
a class pointer may take offset when the casting is done, and multiple inheritance is involved with the class请发布代码示例。pointer may take offset是什么意思?when the casting is done- 什么选角?什么是铸造的?到哪种类型,从哪种类型?multiple inheritance is involved- 如何参与? -
@KamilCuk 很抱歉我的问题是关于 c++ 编程中的一些抽象概念。我考虑为其添加一些示例,但已经发布了带有具体示例的好答案。
标签: c++ pointers casting polymorphism language-lawyer