简体   繁体   中英

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...

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.

#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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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