![](/img/trans.png)
[英]warning C4715: 'operator==' : not all control paths return a value
[英]Warning C4715 not all control paths return a value - Cant find out what may be wrong in the code
我的問題是我再次收到警告 C4715,但我不知道為什么......
我知道可能的未定義行為和已經檢查的定義。 請幫助有需要的新手。
#edit - 我當然缺少“算法”,但這並不能解決問題。
#include <iostream>
#include <vector>
int solve(std::vector<int> v) {
for (int i = 0; i < v.capacity(); i++) {
auto result1 = std::find(v.begin(), v.end(), -v[i]);
if (result1 != v.end())
std::cout << "v contains the opposite of: " << v[i] << '\n';
else {
std::cout << "v doesnt have match to: " << v[i] << '\n';
return v[i];
}
}
}
int main() {
std::vector<int> v{ {1,-1,2,-2,3} };
std::cout << solve(v);
return 0;
}
“如果 for 循環結束,則沒有回報” - 歸功於 @Berto99
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.