好的,这是我的代码:

StatusType System::AddJobSearcher(void *DS, int engineerID, int reqSalary) {
    if(DS == NULL || engineerID < 0 || reqSalary < 0) return INVALID_INPUT;
    System* system = DS;
    Engineer* engineer = new Engineer(engineerID, reqSalary);
    if(!engineer) return ALLOCATION_ERROR;
    if(system->All.isIn(*engineer->generateIdKey())) {
        delete(engineer);
        return FAILURE;
    }
    system->All.insert(*engineer->generateIdKey(), *engineer);
    return SUCCESS;
}


现在,系统是一个类,而DS应该是指向该类的指针。
当我尝试将新创建的系统指向DS(System * system = DS;)时,我得到:


  从'void *'到'System *'的无效转换[-fpermissive]


我该如何解决

最佳答案

因为您知道DS将是System*类型,所以您应该更改参数类型:

StatusType System::AddJobSearcher(System* DS, int engineerID, int reqSalary) {
//                                ^^^^^^


而且,如果您碰巧将void*作为第一个参数传递,则应重构代码,以免不必要。

10-05 23:01