错误:指定的返回类型冲突,与通常不同
error: conflicting return type specified, different than usual
我是计算机科学专业的学生。我知道"指定的返回类型冲突"通常意味着你在声明函数之前使用它,但这一个有点不同。由于严格的分配准则,我正在实现一个任务调度器(我们自己的多线程),在一个名为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;
}
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 从不同线程使用int64的不同字节安全吗
- valgrind-hellgrind与泄漏检查的结果不同
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 函数向量_指针有不同的原型,我可以构建一个吗
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- 访问者访问变体并返回不同类型时出错
- #为""定义宏;静态";针对不同的上下文
- 写入位置0x0000000C时发生访问冲突
- C 和 C++ 中开关语句的案例标签的常量值,但显示不同的行为
- 冲突声明/重新定义:不同的基本类型
- 名称名称空间和类模板之间的冲突:不同的编译器行为
- 常量值与数组上的常量不同
- 当我的程序有两个不同的QGLWidget时,访问冲突
- 错误:指定的返回类型冲突,与通常不同
- 在代码的不同部分中获取访问冲突错误
- 128 位 MD5 在不同数量的文件(例如 1000 万或 5000 万)上的冲突率是多少?
- c++:不同链接库中定义的相同函数的运行时冲突
- 不同库之间的命名冲突
- 避免不同线程发生阻塞冲突的简单方法