There is a dynamic list search function that writes pointers to those elements in which the value of the selected data field matches the search query. According to the results of the work, it should return true
if the vector has at least one element, or false
if the vector is empty. The program, in the scenarios I have conceived, works correctly, but the compiler's warning (Visual Studio Community 2019) strains me warning C4715: DynamicList::search: значение возвращается не при всех путях выполнения
. I just can not understand why he swears, because after the end of the cycle, the function continues its execution. Is this because of the looped conditions?
bool DynamicList::search(unsigned int search_key, unsigned int key_numeric) { DynamicListElement *current_element = this->first_element; while (current_element != nullptr) { if (search_key == NUMBER) { if (current_element->getNumber() == key_numeric) { this->search_buffer.push_back(current_element); //std::vector<DynamicListElement*> search_buffer } } current_element = current_element->getNextElement(); } if (this->search_buffer.size() == 0) { current_element = nullptr; return false; } else if (this->search_buffer.size() > 0) { current_element = nullptr; return true; } }
I also tried using the .empty()
method in conditions, but the warning persisted.
UPD: Used return !this->search_buffer.empty();
instead of both conditions at the end.