標籤:amp 指標 include str 範圍 return ica word []
// 繼承.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
struct person{
int age;
int sex;
};
struct student:person{
int grade;
int intst;
};
void test(){
//person per;
//per.age=1;
//per.age=2;
/*
00401028 mov dword ptr [ebp-8],1
0040102F mov dword ptr [ebp-8],2
*/
student xm;
xm.age=1;
xm.grade=2;
xm.intst=3;
xm.sex=4;
/*00401028 mov dword ptr [ebp-10h],1
0040102F mov dword ptr [ebp-8],2
00401036 mov dword ptr [ebp-4],3
0040103D mov dword ptr [ebp-0Ch],4
*/
//xm.age=12;
//xm.sex=13;
//xm.age=14;
//person* p1=&xm;
//printf("%d\n",p1->age);//可以用父類的指標指向子類的對象,但是只能訪問父類的成員,而且安全,強制類型轉化之後可以用子類的指標指向父類的對象
//但是不安全,因為子類指標所能表示的範圍大於父類對象所表示的範圍,
//student* p2=(student*)&per;
//printf("%d\n",p2->age);
}
int main(int argc, char* argv[])
{
test();
printf("Hello World!\n");
return 0;
}
//繼承的本質就是成員的的複製,在子類初始化時,會將父類擁有的成員也複製到子類中
C+繼承