首页 > 解决方案 > 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?

标签: c++oopstatic

解决方案


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;
}

推荐阅读