error:control reaches end of non-void function [-Werror=return-type]

Posted suzannehuang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了error:control reaches end of non-void function [-Werror=return-type]相关的知识,希望对你有一定的参考价值。

在做LeetCode上的题目时,出现了这个错误,

原代码如下:

 1 class Solution {
 2 public:
 3     vector<int> twoSum(vector<int>& nums, int target) {
 4         vector<int> v;
 5         unordered_map<int, int> m; 
 6         for(int i=0;i<nums.size();++i)
 7         {
 8             int tt=target-nums[i];
 9             if(m.find(tt)!=m.end())
10             {
11                  v.push_back(m[tt]);
12                 v.push_back(i);
13                 return v;
14             }  
15             else
16                     m[nums[i]]=i;
17         }
18         //return v;
19     }
20 };

可以看到18行被我注释掉了,就是这行缺失导致出现程序可能不会返回值。

以上是关于error:control reaches end of non-void function [-Werror=return-type]的主要内容,如果未能解决你的问题,请参考以下文章

Mongodb: com.mongodb.MongoSocketReadException: Prematurely reached end of stream

EOFError: Compressed file ended before the end-of-stream marker was reached

解决异常:com.mongodb.MongoSocketReadException: Prematurely reached end of stream

记一次spring boot中MongoDB Prematurely reached end of stream的异常解决

warning: control reaches end of non-void function

ruby on rails模拟HTTP请求错误发生:end of file reached