简体   繁体   English

警告 C4715 并非所有控制路径都返回值 - 无法找出代码中可能出现的问题

[英]Warning C4715 not all control paths return a value - Cant find out what may be wrong in the code

My problem is that I'm getting the warning C4715 again and I have no clue why...我的问题是我再次收到警告 C4715,但我不知道为什么......

I'm aware of possible undefined beahviour and already checked definitions.我知道可能的未定义行为和已经检查的定义。 Please help a newbie in need.请帮助有需要的新手。

#edit - of course im missing 'algorithm' but that doesnt solve problem. #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;
}

" if the for loop ends, you have no return " - credit to @Berto99 “如果 for 循环结束,则没有回报” - 归功于 @Berto99

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM