黑马程序员的 通讯录管理系统访问权限冲突

自己写了一个 判断输入的职工编号是否存在 的代码,不知道为什么每次添加到第三次的时候就会出现,有大佬帮我看看问题出在哪里吗5555

void workerManager::addPerson()
{
    cout << "请输入要添加的员工数量:" << endl;
    int Num = 0;
    cin >> Num;
    
    if (Num > 0)
    {
        //计算新空间大小
        int newSize = empNum + Num;
        //申请新空间
        AbstractWorker ** newspace = new AbstractWorker*[newSize];

        //将原有数据放到新空间
        if (this->workerArray != NULL)
        { 
            for (int i = 0; i < this->empNum; i++)
            { 
                newspace[empNum+i] = this->workerArray[i];
            }
        }

        for (int i = 0; i < Num; i++)
        {
            int num;
            while(true)
            { 
                cout << "请输入第" << i + 1 << "位职工的编号:" << endl;
                int temp;
                cin >> temp;
                //检测id是否存在
                bool isIdExist=false;
                if (this->workerArray != NULL)
                {
                    for (int i = 0; i < empNum; i++)
                    {
                        if ( temp==workerArray[i]->m_ID )//这个地方报错:0x003FDBC4 处(位于 
                                                         //基于多态的职工管理系统.exe 中)引 
                                                         //发的异常: 0xC0000005: 读取位置 
                                                         //0xCDCDCDD1 时发生访问冲突。

                        {
                            isIdExist = true;
                        }
                    }
                }
                if (isIdExist)
                {
                    cout << "编号已存在,请重新输入" << endl;
                }
                else
                {
                    num = temp;
                    break;
                }
            }

            cout << "请输入第" << i + 1 << "位职工的姓名:" << endl;
            string name;
            cin >> name;

            cout << "请输入第" << i + 1 << "位职工的职位:" << endl;
            cout << "1、老板" << endl;
            cout << "2、经理" << endl;
            cout << "3、职工" << endl;

            int dNum;
            cin >> dNum;

            switch (dNum)
            {
            case 1:
                newspace[this->empNum+i] = new Boss(num, dNum, name);
                break;

            case 2:
                newspace[this->empNum + i] = new Manager(num, dNum, name);
                break;

            case 3:
                newspace[this->empNum + i] = new Worker(num, dNum, name);
                break;

            default:
                break;
            }
        }
        //释放原有空间
        delete this->workerArray;
        //将原有空间置为空
        this->workerArray = NULL;
        //更新指针指向
        this->workerArray = newspace;
        empNum = newSize;

        cout << "已成功添加" <<Num<<"位员工"<< endl;
    }
    else
    {
        cout << "输入有误" << endl;
    }

    system("pause");
    system("cls");
}

 

博主你好,请问你有解决这个问题吗,代码都没问题,也遇到了访问冲突