c++ - 错误 : conflicting return type specified, 与平常不同

标签 c++ compiler-errors

我是一名计算机科学专业的学生。我知道“指定的返回类型冲突”通常意味着您在声明函数之前使用该函数,但这个有点不同。由于严格的分配准则,我正在实现一个任务调度程序(我们自己的多线程程序),并且在一个名为 Task 的类中,在 Task.h 中我们有:

void Task::Start(){
    int * returnval = new int;
    *returnval = pthread_create(&thread_id,NULL,tfunc,this);        
    delete returnval;
}

然后在另一个文件schedulable.h中,我们有:

int Schedulable::Start(){ 
    try{ 
        Task::Start();
        return 0; 
    }catch(int e) { return 1; } 
}

当我编译它时,出现“返回类型冲突”错误:

In file included from scheduler.H:59, from task_test_step2.cpp:9: schedulable.H:162: error: conflicting return type specified for ‘virtual int Schedulable::Start()’ task.h:157: error: overriding ‘virtual void Task::Start()’

有什么想法可以让这种情况停止发生吗?

最佳答案

问题在于 Schedulable::Start 覆盖 Task::Start 并将返回类型从 void 更改为 int。您可能想让 Task::Start 也返回一个 int:

int Task::Start(){
    // no need to use new here!
    int returnval = pthread_create(&thread_id,NULL,tfunc,this);        
    return returnval;
}

关于c++ - 错误 : conflicting return type specified, 与平常不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8379525/

相关文章:

c++ - 模板类型参数的 Sizeof 成员变量

c++ - 如何通过扩展以下类型特征来删除 decltype(& MyClass::func) 部分?

C++ 正则表达式 header 未注册 Netezza UDF

c++ - 为什么这段代码不能使用 MS 编译器编译?

function - Verilog 函数 - 无法找出我的错误

c++ - 无法加载PDB符号(未加载igvk32.pdb)

c++ - 如何在 dlib 正面面部检测器中拆分级联级别?

c++ - 使用 winsock 的奇怪连接超时

visual-studio - Visual Studio 已停止工作 - 在 Win 7 上

scala - Int上的匹配表达式并不详尽