写入到缓冲区溢出,可写大小为4字节,但可能写入了8字节
如果换成64位就不报错,32位下就会有这个问题。void WorkManager::AddEmp()
{
cout << "请输入添加人数:" << endl;
int AddNum = 0;
cin >> AddNum;
if (AddNum > 0)
{
int newSize = m_EmpNum + AddNum;
Worker** newSpace = new Worker * ;
//旧数据放入新地址
if (this->EmpArr != NULL)
{
for (int i = 0; i < this->m_EmpNum; i++)
{
newSpace = this->EmpArr;
}
}
//输入新数据
for (int i = 0; i < AddNum; i++)
{
int ID;
string name;
int dSelecte;
cout << "Please input " << i + 1 << " worker ID:" << endl;
cin >> ID;
cout << "Please input " << i + 1 << " worker name:" << endl;
cin >> name;
cout << "Please input " << i + 1 << " worker post:" << endl;
cout << "1.employee" << endl;
cout << "2.manager" << endl;
cout << "3.boss" << endl;
Worker* worker = NULL;
cin >> dSelecte;
switch (dSelecte)
{
case 1:
worker = new Employee(ID, name, dSelecte);
break;
case 2:
worker = new Manager(ID, name, dSelecte);
break;
case 3:
worker = new Boss(ID, name, dSelecte);
break;
default:cout << "Input erro" << endl;
break;
}
newSpace = worker;
}
//删除原有空间
delete[]this->EmpArr;
//指向新空间
this->EmpArr = newSpace;
//更新新大小
this->m_EmpNum = newSize;
cout << "添加成功" << endl;
save();
}
else
{
cout << "输入数据有误" << endl;
}
cout << "按任意键继续" << endl;
system("pause");
system("cls");
}
页:
[1]