struct Person
{
int age;
int sex;
};
struct Teacher:Person//继承 { int level; int classid; }; int main(int argc, char* argv[]) {
Teacher t;t.age = 1;t.sex = 2;t.level = 3;t.classid = 4;int x = sizeof(t);// t 的大小为16 ,t继承了person的数据return 0;
}

```cpp
Teacher t;
t.age = 1;
005F48C2 mov dword ptr [t],1
t.sex = 2;
005F48C9 mov dword ptr [ebp-14h],2
t.level = 3;
005F48D0 mov dword ptr [ebp-10h],3
t.classid = 4;
005F48D7 mov dword ptr [ebp-0Ch],4
int x = sizeof(t);
005F48DE mov dword ptr [x],10h
return 0;
005F48E5 xor eax,eax
}
重载
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
struct Person
{
int age;
int sex;
};
struct Teacher:Person//继承
{
int age;
int classid;
};
int main(int argc, char* argv[]) {
Teacher t;
t.age = 1;
t.Person::age = 2; //同名时
t.sex = 2;
t.classid = 4;
int x = sizeof(t);
return 0;
}
Teacher t;
t.age = 1;
00D848C2 mov dword ptr [ebp-10h],1
t.Person::age = 2;
00D848C9 mov dword ptr [t],2
t.sex = 2;
00D848D0 mov dword ptr [ebp-14h],2
t.classid = 4;
00D848D7 mov dword ptr [ebp-0Ch],4
int x = sizeof(t);
00D848DE mov dword ptr [x],10h
return 0;
00D848E5 xor eax,eax
}

多继承 -多层继承
多重继承增加程序复杂度,不建议使用

