马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
如果换成64位就不报错,32位下就会有这个问题。
void WorkManager::AddEmp()
{
cout << "请输入添加人数:" << endl;
int AddNum = 0;
cin >> AddNum;
if (AddNum > 0)
{
int newSize = m_EmpNum + AddNum;
Worker** newSpace = new Worker * [newSize];
//旧数据放入新地址
if (this->EmpArr != NULL)
{
for (int i = 0; i < this->m_EmpNum; i++)
{
newSpace[i] = this->EmpArr[i];
}
}
//输入新数据
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[this->m_EmpNum + i] = worker;
}
//删除原有空间
delete[]this->EmpArr;
//指向新空间
this->EmpArr = newSpace;
//更新新大小
this->m_EmpNum = newSize;
cout << "添加成功" << endl;
save();
}
else
{
cout << "输入数据有误" << endl;
}
cout << "按任意键继续" << endl;
system("pause");
system("cls");
}
|