得到警告:当试图编译时,控件可能会到达非void函数的末尾
Getting warning: control may reach end of non-void function when trying to compile
这不会编译,我不知道其中的错误:
template<class Type> Type ArrayPQ<Type>::removeMin(void ) throw(exception)
{
if (isEmpty())
{
cout << "Empty Priority Queuen";
}
else
{
Type min = array[0];
array[0] = array[heap];
heap--;
minHeapify(0);
return min;
}
}
我一直收到这样的警告:
In file included from runtime_analysis.cpp:7:
./PQ3.h:57:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
./PQ3.h:114:9: note: in instantiation of member function 'ArrayPQ<int>::removeMin' requested here
removeMin();
^
runtime_analysis.cpp:67:12: note: in instantiation of member function 'ArrayPQ<int>::DeleteAll' requested here
ArrPQ->DeleteAll();
^
1 warning generated.
每当我运行代码时,我都会收到一个错误。
您收到警告是因为您保留了可能无法到达返回语句的开放场景。目前您只有一个,在else语句范围内。在else语句的范围之外,您将返回什么?
如果队列为空,则应抛出异常:
class myexception: public exception
{
virtual const char* what() const throw()
{
return "Empty Priority Queue";
}
} myex;
然后将空复选框改为:
if (isEmpty())
{
throw myex;
}
相关文章:
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- 在c++类上调用void函数
- C++为什么尽管我调用了void函数,它却不起作用
- 如何从void函数输出字符串
- 如何将指针从一个void函数传递到另一个C++
- 为什么我在使用void函数时得到错误代码C2276
- 指针没有更新它在void函数内部指向的值
- 为什么我们要为avl树实现返回一个指向节点的指针,而不是void函数
- void 函数可以传递值参数吗?
- 在 void 函数中使用 #include 变量C++
- 如何在 C++ 中将 void 函数传递给 void 指针
- 使用运算符调用 void 函数时出错<set>
- C++ 随机数生成器:尝试将结果作为向量获取,但通过制作 void 函数来执行此操作而出现错误
- C++ :: 如何捕获由 void 函数创建的矩阵
- 如何将一个 void 函数传递给另一个 void 函数?
- 当我使用 void 函数的返回值(通过强制转换函数指针)时,究竟会发生什么?
- C++命名空间中调用 void 函数的错误
- 当数组位于两个循环之间时,您可以调用数组的 void 函数吗?
- 结构新手,我对如何从 void 函数中返回值并将其放入另一个函数感到困惑
- 查找素数:错误:控件到达非void函数的末尾