c++ - No return statement warning in function returning non-void
问题描述
This is lines of my code that I get a warning saying "No return statement warning in function returning non-void" I have declared total as: static int total;
int Rooms::getTotalEmptyRooms() {
return total;
}
int Rooms::setTotalEmptyRooms(int i) { //warning here
total = i;
}
Any suggestion how can I get rid of the warning?
解决方案
When you declare it as an int, it has to have return with an in inside the function.
Either change the head to
void Rooms::setTotalEmptyRooms(int i) {
total = i;
}
or have it return something, like
int Rooms::setTotalEmptyRooms(int i) {
total = i;
return total;
}
推荐阅读
- java - 在 Android Studio 中:如何更新列数据?
- rust - Rust 模式匹配如何确定绑定变量是引用还是值?
- bash - 如何监控特定单词的 IPMI SOL 输出,然后回显一个短语?
- c - 如何在 C 中完全重新分配二维数组?
- javascript - 是否有替代 console.log() 的方法,它可以让您打印并更新一行而不是向控制台发送垃圾邮件?
- python - 包安装在 anaconda\lib\site-packages 并在 spyder 中找到,但不在 jupyter 笔记本中
- c# - 如何在后台运行代码时将数据提供给 div 标签
- python - Python函数在循环内不起作用
- python - 我怎样才能打印这个类的属性;;结果没有按预期返回?
- haskell - Haskell:理解 foldl 函数