[英]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.