Schrieffer.zsy 2021-02-07 16:58 采纳率: 93.8%
浏览 27
已结题

系统一直卡在ShowJob函数的调用上面,为什么系统会说发生访问冲突?

#include<iostream>
#include<string>
#include<fstream>
using namespace std;
class Staff
{
public:
	string m_Code;
	string m_Name;
	string m_DepartmentCode;
	string m_Job;
	string m_Position;
	Staff* ptr_Position;
	virtual string ShowJob() 
	{ 
		return 0;
	}
};
class NormalEmployee :public Staff
{
public:
	string m_Job;
	string m_Position;
	NormalEmployee()
	{
		this->m_Job = "完成经理交付的任务";
		this->m_Position = "普通员工";
	}
	virtual string ShowJob()
	{
		return this->m_Job;
	}
};
class Manager :public Staff
{
public:
	string m_Job;
	string m_Position;
	Manager()
	{
		this->m_Job = "完成老板交付的任务,并将任务下发给员工";
		this->m_Position = "经理";
	}
	virtual string ShowJob()
	{
		return this->m_Job;
	}
};
class Boss :public Staff
{
public:
	string m_Job;
	string m_Position;
	Boss()
	{
		this->m_Job = "管理公司所有事务";
		this->m_Position = "老板";
	}
	virtual string ShowJob()
	{
		return this->m_Job;
	}
};

int len=0;
Staff AllStaff[1000];
void AddStaff(Staff* arr,int& size)
{
	string name;
	string code,code1;
	cout << "请输入员工姓名" << endl;
	cin >> name;
	arr[size].m_Name = name;
	cout << "请输入职工编号" << endl;
	cin >> code;
	arr[size].m_Code = code;
	cout << "请输入部门编号" << endl;
	cin >> code1;
	arr[size].m_DepartmentCode = code1;
	cout << "请输入职工岗位" << endl;
	cin >> name;
	arr[size].m_Position = name;
	if (arr[size].m_Position == "普通员工")
	{
		arr[size].ptr_Position = new NormalEmployee;
		arr[size].m_Job = arr[size].ShowJob();
	}
	else if (arr[size].m_Position == "经理")
	{
		arr[size].ptr_Position = new Manager;
		//arr[size].m_Job = arr[size].ShowJob();
	}
	else if (arr[size].m_Position == "老板")
	{
		arr[size].ptr_Position = new Boss;
		arr[size].m_Job = arr[size].ShowJob();
	}
	size++;
	cout << "添加成功!" << endl;
}
int main()
{
	int choice;
	int i = 0;
	PrintMenu();
	cin >> choice;
	while (true)
	{
		if (i != 0)
		{
			PrintMenu();
			cin >> choice;
		}
		switch (choice)
		{
		case 1:
			cout << "欢迎您的再次使用!" << endl;
			return 0;
		case 2:
			AddStaff(AllStaff,len);
			break;
		case 3:
			ShowStaff(AllStaff, len);
			break;
		case 4:
			DeleteStaff(AllStaff, len);
			break;
		case 5:
			ModifyStaff(AllStaff, len);
			break;
		case 6:
			SearchStaff(AllStaff, len);
			break;
		case 7:
			Demendorder(AllStaff, len);
			break;
		case 8:
			DeleteAll(len);
			break;
		default:
			system("cls");
			cout << "\t请输入正确的数字选项!" << endl;
			cout << "\t";
			system("pause");
			break;
		}
		i++;
		system("cls");
	}
}
  • 写回答

4条回答 默认 最新

  • 锁柱子 2021-02-07 17:17
    关注

    把报错信息也贴出来大家一起看看呗

    评论

报告相同问题?

悬赏问题

  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,
  • ¥15 spaceclaim模型变灰色
  • ¥15 求一份华为esight平台V300R009C00SPC200这个型号的api接口文档
  • ¥15 就很莫名其妙,本来正常的Excel,突然变成了这种一格一页
  • ¥15 字符串比较代码的漏洞
  • ¥15 欧拉系统opt目录空间使用100%
  • ¥15 ul做导航栏格式不对怎么改?