菱形繼承的識別

2021-07-22 18:07:04 字數 2068 閱讀 4416

子類的構造

csofabed sofabed;

0041478e 6a 01 push 1 ;構造祖父類的標誌 true表示構造

00414790 8d 4d c8 lea ecx,[sofabed]

00414793 e8 1f d0 fe ff call csofabed::csofabed (04017b7h)

csofabed::csofabed:

004017b7 e9 c4 c9 00 00 jmp csofabed::csofabed (040e180h)

class csofabed : public csofa, public cbed;

// 子類沙發床定義,派生自csofa、cbed類,等同與類d

class csofabed : public csofa, public cbed

0040e256 c7 45 fc ff ff ff ff mov dword ptr [ebp-4],0ffffffffh

0040e25d 8b 45 ec mov eax,dword ptr [this]

0040e260 8b 4d f4 mov ecx,dword ptr [ebp-0ch]

// 菱形結構分析

// 定義家具類,等同於類a

class cfurniture

virtual ~cfurniture()

virtual

int getprice();

protected:

int m_nprice; // 家具類成員變數

};// 定義沙發類,繼承自cfurniture,等同與類b

class csofa : virtual

public cfurniture

virtual ~csofa()

virtual

int getcolor()

virtual

int sitdown()

protected:

int m_ncolor; // 沙發類成員變數

};// 定義床類,繼承自cfurniture,等同與類c

class cbed : virtual

public cfurniture

virtual ~cbed()

virtual

int getarea()

virtual

int sleep()

protected:

int m_nlength; // 床類成員變數

int m_nwidth;

};// 子類沙發床定義,派生自csofa、cbed類,等同與類d

class csofabed : public csofa, public cbed

virtual ~csofabed()

virtual

int sitdown()

virtual

int sleep()

virtual

int getheight()

protected:

int m_nheight; // 沙發類成員變數

};

00498f54 3f aas

00498f55 2b 40 00 sub eax,dword ptr [eax]

00498f58 9a 3e 40 00 9d 22 40 call 4022:9d00403e

00498f5f 00

00498e5c 82 2e 40 sub byte ptr [esi],40h

00498e5f 00 25 13 40 00 c4

菱形繼承 菱形虛擬繼承

菱形繼承 鑽石繼承 模型 拿如下 舉例 class person class student public person class teacher public person class graduate public student,public teacher void test 當派生類gr...

菱形繼承和菱形虛繼承

繼承是c 的一大特點,我們通過菱形繼承和菱形虛繼承對繼承進行進一步的分析。菱形繼承 建立乙個基類a讓b1和b2公有繼承於它,讓c公有繼承b1和b2。class a a int a class b1 public a b1 int b1 class b2 public a b2 int b2 clas...

複雜的菱形繼承及菱形虛擬繼承

乙個子類只有乙個直接父類時稱這個繼承關係為單繼承 乙個子類有兩個或兩個以上的直接父類時稱這個繼承方式為多繼承 菱形繼承是多繼承的一種特殊情況 菱形繼承的問題 1.冗餘 2.二義性 class person class student public person class teacher publi...