16,551
社区成员
发帖
与我相关
我的任务
分享
#include <stdlib.h>
class CPerson
{
};
class CFarmer : public CPerson
{
public:
int m_iAge;
};
int main()
{
CPerson person;
CFarmer *pFarmer = (CFarmer*)&person;
pFarmer->m_iAge = 3;
system("pause");
return 0;
}
将父类指针赋予子类指针,子类指针调用子类公有成员,编译通过,但运行结束后弹出错误:
Stack around the variable 'person' was corrupted
中文翻译就是“在变量“person”周围的堆栈已损坏”
这个例子跟我最开始的例子有什么区别吗?
可以帮忙详解一下MFC中的动态类创建机制吗?