为什么会发生切割?
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
class a
{
};
class b : public a
{
};
class c : public a
{
};
int GetType(a & A)
{
return 0;
}
int GetType(b & B)
{
return 1;
}
int GetType(c & C)
{
return 2;
}
int main(int argc, char* argv[])
{
printf("Hello World!\n");
a A;
printf("%d\n", GetType(A));
b B;
printf("%d\n", GetType(B));
c C;
printf("%d\n", GetType(C));
a *pA = &C;
printf("%d\n", GetType(*pA));
return 0;
}
运行结果是:
Hello World!
0
1
2
0
问题:为什么GetType(*pA) 得到0?难道发生切割了吗?为什么这样?