Cpp 对象模型探索 / 含有虚基类的类的内存布局
生活随笔
收集整理的這篇文章主要介紹了
Cpp 对象模型探索 / 含有虚基类的类的内存布局
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、栗子
class Grand { public:int i_grand_ = 8; };class Parent1 : public virtual Grand { public:int i_parent1_ = 9; };class Parent2 : public virtual Grand { public:int i_parent2_ = 10; };class Son : public Parent1,public Parent2 { public:int i_son_ = 11; };int main() {return 0; }? ? ? ?打開?Developer Command Prompt for VS 2019 ,當前目錄切換到該工程所在目錄,執行如下指令:
cl /d1 reportSingleClassLayoutParent1 test1.cpp1、cl "l"是小寫的“L”。 2、d1 “1”是數字“1”。 3、“reportSingleClassLayoutParent1” 是 “reportSingleClassLayout” + 類名,即:要查看數據結構的/類的名字。 4、"test1.cpp",該類所在的代碼文件。二、Parent 類的內存布局
? ? ? ?執行指令
cl /d1 reportSingleClassLayoutParent1 test1.cpp? ? ? ?得到如下圖所示的結果
? ? ? ?根據上圖得到下圖所示的 Parent1 類的內存布局。
三、Son 類的內存布局
? ? ? ? 執行指令
cl /d1 reportSingleClassLayoutSon test1.cpp? ? ? ?得到如下圖所示的結
? ? ? 根據上圖得到下圖所示的 Son?類的內存布局。
四、總結
五、其他
(SAW:Game Over!)
總結
以上是生活随笔為你收集整理的Cpp 对象模型探索 / 含有虚基类的类的内存布局的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Cpp 对象模型探索 / 系列文章的索引
- 下一篇: Cpp 对象模型探索 / 虚基类表作用